ruby-changes:2436
From: ko1@a...
Date: 15 Nov 2007 12:21:02 +0900
Subject: [ruby-changes:2436] matz - Ruby:r13927 (trunk): * lib/cgi/session.rb (CGI::Session::FileStoRe: :restore): use
matz 2007-11-15 12:20:52 +0900 (Thu, 15 Nov 2007) New Revision: 13927 Modified files: trunk/ChangeLog trunk/lib/cgi/session.rb 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/trunk/lib/cgi/session.rb?r1=13927&r2=13926 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13927&r2=13926 Index: ChangeLog =================================================================== --- ChangeLog (revision 13926) +++ ChangeLog (revision 13927) @@ -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] + Thu Nov 15 12:14:53 2007 Yukihiro Matsumoto <matz@r...> * tool/compile_prelude.rb (c_esc): need to escape closing brace. Index: lib/cgi/session.rb =================================================================== --- lib/cgi/session.rb (revision 13926) +++ lib/cgi/session.rb (revision 13927) @@ -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