Permalink
Browse files

merge revision(s) 13935:

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


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@16939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
shyouhei committed Jun 7, 2008
1 parent a137d53 commit f6f86c8bb66ac800c734c79607c410e4c57c3f60
Showing with 19 additions and 5 deletions.
  1. +6 −0 ChangeLog
  2. +12 −4 lib/cgi/session.rb
  3. +1 −1 version.h
View
@@ -1,3 +1,9 @@
+Sun Jun 8 03:52:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/cgi/session.rb (CGI::Session::FileStore::restore): use
+ lockfile for exclusive locks. a patch from <tommy AT tmtm.org>.
+ [ruby-dev:32296]
+
Sun Jun 8 03:49:15 2008 Tanaka Akira <akr@fsij.org>
* missing/isinf.c (isinf): don't define if the macro is defined.
View
@@ -391,15 +391,17 @@ def restore
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)
@hash[CGI::unescape(k)] = CGI::unescape(v)
end
ensure
f.close unless f.nil?
+ lockf.close if lockf
end
end
@hash
@@ -409,13 +411,17 @@ def restore
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
@@ -426,6 +432,8 @@ def close
# 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
View
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-08"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20080608
-#define RUBY_PATCHLEVEL 145
+#define RUBY_PATCHLEVEL 146
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8

0 comments on commit f6f86c8

Please sign in to comment.