[前][次][番号順一覧][スレッド一覧]

ruby-changes:2444

From: ko1@a...
Date: 15 Nov 2007 18:18:13 +0900
Subject: [ruby-changes:2444] matz - Ruby:r13935 (ruby_1_8): * lib/cgi/session.rb (CGI::Session::FileStoRe: :restore): use

matz	2007-11-15 18:17:58 +0900 (Thu, 15 Nov 2007)

  New Revision: 13935

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/cgi/session.rb
    branches/ruby_1_8/version.h

  Log:
    * lib/cgi/session.rb (CGI::Session::FileStore::restore): use
      lockfile for exclusive locks.  a patch from <tommy AT tmtm.org>.
      [ruby-dev:32296]

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/cgi/session.rb?r1=13935&r2=13934
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13935&r2=13934
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=13935&r2=13934

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 13934)
+++ ruby_1_8/ChangeLog	(revision 13935)
@@ -1,3 +1,9 @@
+Thu Nov 15 12:19:14 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* lib/cgi/session.rb (CGI::Session::FileStore::restore): use
+	  lockfile for exclusive locks.  a patch from <tommy AT tmtm.org>.
+	  [ruby-dev:32296]
+
 Wed Nov 14 01:52:59 2007  Tanaka Akira  <akr@f...>
 
 	* missing/isinf.c (isinf): don't define if the macro is defined.
Index: ruby_1_8/version.h
===================================================================
--- ruby_1_8/version.h	(revision 13934)
+++ ruby_1_8/version.h	(revision 13935)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-11-14"
+#define RUBY_RELEASE_DATE "2007-11-15"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20071114
+#define RUBY_RELEASE_CODE 20071115
 #define RUBY_PATCHLEVEL 5000
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2007
 #define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 14
+#define RUBY_RELEASE_DAY 15
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8/lib/cgi/session.rb
===================================================================
--- ruby_1_8/lib/cgi/session.rb	(revision 13934)
+++ ruby_1_8/lib/cgi/session.rb	(revision 13935)
@@ -397,8 +397,9 @@
 	unless @hash
 	  @hash = {}
           begin
+            lockf = File.open(@path+".lock", "r")
+            lockf.flock File::LOCK_SH
 	    f = File.open(@path, 'r')
-	    f.flock File::LOCK_SH
 	    for line in f
 	      line.chomp!
 	      k, v = line.split('=',2)
@@ -406,6 +407,7 @@
 	    end
           ensure
 	    f.close unless f.nil?
+            lockf.close if lockf
           end
 	end
 	@hash
@@ -415,13 +417,17 @@
       def update
 	return unless @hash
         begin
-	  f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)
-	  f.flock File::LOCK_EX
+          lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
+	  lockf.flock File::LOCK_EX
+          f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
    	  for k,v in @hash
 	    f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(v))
 	  end
+          f.close
+          File.rename @path+".new", @path
         ensure
-          f.close unless f.nil?
+          f.close if f and !f.closed?
+          lockf.close if lockf
         end
       end
 
@@ -432,6 +438,8 @@
 
       # Close and delete the session's FileStore file.
       def delete
+        File::unlink @path+".lock" rescue nil
+        File::unlink @path+".new" rescue nil
         File::unlink @path
       rescue Errno::ENOENT
       end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]