Added file lock and improved read of file.

This commit is contained in:
Martin Edenhofer 2013-04-15 16:09:07 +02:00
parent 9283d70e9e
commit 57d1d8288b

View file

@ -66,15 +66,14 @@ module Session
data = nil data = nil
return if !File.exist? session_file return if !File.exist? session_file
File.open( session_file, 'rb' ) { |file| File.open( session_file, 'rb' ) { |file|
all = '' file.flock( File::LOCK_EX )
while line = file.gets all = file.read
all = all + line
end
begin begin
data = Marshal.load( all ) data = Marshal.load( all )
rescue rescue
return return
end end
file.flock( File::LOCK_UN )
} }
return data return data
end end