* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@13927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-11-15 03:20:52 +00:00
Родитель 4c56aaa162
Коммит af2ab37334
2 изменённых файлов: 18 добавлений и 4 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Thu Nov 15 12:19:14 2007 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]
Thu Nov 15 12:14:53 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* tool/compile_prelude.rb (c_esc): need to escape closing brace.

Просмотреть файл

@ -397,8 +397,9 @@ class CGI
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 @@ class CGI
end
ensure
f.close unless f.nil?
lockf.close if lockf
end
end
@hash
@ -415,13 +417,17 @@ class CGI
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 @@ class CGI
# 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