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 5f994f3 Simplify; let nil mean no error 5f994f3 is described below commit 5f994f36b9d6810db48dfa00cf3103f416a70ac3 Author: Sebb <s...@apache.org> AuthorDate: Wed Jul 4 08:47:03 2018 +0100 Simplify; let nil mean no error --- lib/whimsy/lockfile.rb | 19 +++++++++++++------ www/project/icla/views/actions/discuss.json.rb | 10 +++++++--- www/project/icla/views/actions/vote.json.rb | 12 ++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/whimsy/lockfile.rb b/lib/whimsy/lockfile.rb index 57d5515..02fafbf 100644 --- a/lib/whimsy/lockfile.rb +++ b/lib/whimsy/lockfile.rb @@ -6,8 +6,8 @@ module LockFile - # create a new file and return an error if it already exists - def self.create_ex(filename, verbose=false) + # create a new file and return an error if it already exists, otherwise nil + def self.create_ex(filename) err = nil begin File.open(filename, File::WRONLY|File::CREAT|File::EXCL) do |file| @@ -16,7 +16,7 @@ module LockFile rescue => e err = e end - return verbose ? [err==nil, err] : err==nil + err end # lock an open file and ensure it gets unlocked @@ -50,11 +50,10 @@ if __FILE__ == $0 name = ARGV.shift || '/tmp/lockfile1' text = "#{Time.now}\n" puts "#{Time.now} #{test} using #{name}" + ret = nil case test when 'create' ret = LockFile.create_ex(name) {|f| f << text} - when 'createShow' - ret = LockFile.create_ex(name, true) {|f| f << text} when 'opena' puts "#{Time.now} Wait lock" ret = LockFile.lockfile(name, 'a', File::LOCK_EX) do |f| @@ -84,6 +83,14 @@ if __FILE__ == $0 else raise "Unexpected test: #{test}" end + puts ret.class.inspect puts ret.inspect - puts File.read(name) + if ret + if Errno::EEXIST === ret + puts "Already exists!" + else + puts "Some other error" + end + end + puts File.read(name) unless ret end diff --git a/www/project/icla/views/actions/discuss.json.rb b/www/project/icla/views/actions/discuss.json.rb index c2da67a..1c1f783 100644 --- a/www/project/icla/views/actions/discuss.json.rb +++ b/www/project/icla/views/actions/discuss.json.rb @@ -47,11 +47,15 @@ token = pmc.name + '-' + date + '-' + Digest::MD5.hexdigest(@iclaemail)[0..5] file_name = '/srv/icla/' + token + '.json' # important not to overwrite any existing files -if LockFile.create_ex(file_name.untaint) do |f| +err = LockFile.create_ex(file_name.untaint) do |f| f.write(JSON.pretty_generate(discussion)) +end +if err + if Errno::EEXIST === err + _error 'There is already a file for that person!' + else + _error err.inspect end -else - _error 'There is already a file for that person!' end # add user and pmc emails to the response diff --git a/www/project/icla/views/actions/vote.json.rb b/www/project/icla/views/actions/vote.json.rb index b80d50d..e6b0306 100644 --- a/www/project/icla/views/actions/vote.json.rb +++ b/www/project/icla/views/actions/vote.json.rb @@ -26,7 +26,7 @@ rescue _focus :iclaemail end # create the vote object -date = Time.now.to_date.to_s +date = Time.now.to_date.to_s # requires 'time' (seems to be pulled in by 'mail') contributor = {:name => @iclaname, :email => @iclaemail} comment = @proposalText + "\n" + @voteComment votes = [{:vote =>'+1', :member => @proposer, :timestamp => date, :comment => comment}] @@ -46,11 +46,15 @@ token = pmc.name + '-' + date + '-' + Digest::MD5.hexdigest(@iclaemail)[0..5] file_name = '/srv/icla/' + token + '.json' # important not to overwrite any existing files -if LockFile.create_ex(file_name.untaint) do |f| +err = LockFile.create_ex(file_name.untaint) do |f| f.write(JSON.pretty_generate(discussion)) +end +if err + if Errno::EEXIST === err + _error 'There is already a file for that person!' + else + _error err.inspect end -else - _error 'There is already a file for that person!' end