Added file lock and improved read of file.
This commit is contained in:
parent
9283d70e9e
commit
57d1d8288b
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue