From 57d1d8288bb65f27c61169c27089cc6c9d8dc617 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 15 Apr 2013 16:09:07 +0200 Subject: [PATCH] Added file lock and improved read of file. --- lib/session.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/session.rb b/lib/session.rb index 78e42fcc7..a805b5fc9 100644 --- a/lib/session.rb +++ b/lib/session.rb @@ -66,15 +66,14 @@ module Session data = nil return if !File.exist? session_file File.open( session_file, 'rb' ) { |file| - all = '' - while line = file.gets - all = all + line - end + file.flock( File::LOCK_EX ) + all = file.read begin data = Marshal.load( all ) rescue return end + file.flock( File::LOCK_UN ) } return data end