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 7e23534  Don't assume that the input is updated in situ
7e23534 is described below

commit 7e235345a37adf35e85559fc6e9b3003b001f462
Author: Sebb <[email protected]>
AuthorDate: Fri Oct 16 20:24:43 2020 +0100

    Don't assume that the input is updated in situ
---
 lib/whimsy/asf/yaml.rb | 5 ++---
 tools/parsemail.rb     | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/whimsy/asf/yaml.rb b/lib/whimsy/asf/yaml.rb
index 995aa2a..f202336 100644
--- a/lib/whimsy/asf/yaml.rb
+++ b/lib/whimsy/asf/yaml.rb
@@ -12,7 +12,7 @@ module YamlFile
   # encapsulate updates to a YAML file
   # opens the file for exclusive access with an exclusive lock,
   # creating the file if necessary
-  # Yields the parsed YAML to the block, and writes the updated
+  # Yields the parsed YAML to the block, and writes the return
   # data to the file
   # The args are passed to YAML.safe_load, and default to [Symbol]
   def self.update(yaml_file, *args)
@@ -20,9 +20,8 @@ module YamlFile
     File.open(yaml_file, File::RDWR|File::CREAT, 0o644) do |file|
       file.flock(File::LOCK_EX)
       yaml = YAML.safe_load(file.read, *args) || {}
-      yield yaml
       file.rewind
-      file.write YAML.dump(yaml)
+      file.write YAML.dump(yield yaml)
       file.truncate(file.pos)
     end
   end
diff --git a/tools/parsemail.rb b/tools/parsemail.rb
index 1a7082c..b1feb02 100755
--- a/tools/parsemail.rb
+++ b/tools/parsemail.rb
@@ -57,4 +57,5 @@ YamlFile.update(yamlfile) do |yaml|
             yaml[k] = v
         end
     end
+    yaml
 end

Reply via email to