You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2018/07/05 00:35:35 UTC
[whimsy] branch master updated: Read-only file lock to ensure file
read safely
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 644295c Read-only file lock to ensure file read safely
644295c is described below
commit 644295cc321a723631f500962ea8d09925488007
Author: Sebb <se...@apache.org>
AuthorDate: Thu Jul 5 01:35:34 2018 +0100
Read-only file lock to ensure file read safely
---
www/project/icla/main.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/www/project/icla/main.rb b/www/project/icla/main.rb
index 21facf0..268111d 100755
--- a/www/project/icla/main.rb
+++ b/www/project/icla/main.rb
@@ -3,6 +3,7 @@
#
require 'whimsy/asf'
+require 'whimsy/lockfile'
require 'wunderbar/sinatra'
require 'wunderbar/vue'
@@ -37,11 +38,14 @@ helpers do
end
def loadProgress(token)
if token
+ data = nil
# read the file corresponding to the token
# the file name is '/srv/<token>.json
filename = '/srv/icla/' + token + '.json'
begin
- JSON.parse(File.read(filename)) # TODO does this need a read lock?
+ LockFile.lockfile(filename) do |f| # shared read
+ data = JSON.parse(File.read(f))
+ end
rescue SystemCallError => e
{
phase: 'error', errorMessage: e.message, errorCode: e.errno
@@ -51,6 +55,7 @@ helpers do
phase: 'error', errorMessage: e.message, errorCode: 999
}
end
+ data
end
end
def getMember(userId)