diff options
Diffstat (limited to 'lib/chef/chef_fs/command_line.rb')
-rw-r--r-- | lib/chef/chef_fs/command_line.rb | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb index 1b6884514a..2aefe2fa88 100644 --- a/lib/chef/chef_fs/command_line.rb +++ b/lib/chef/chef_fs/command_line.rb @@ -266,26 +266,25 @@ class Chef def diff_text(old_path, new_path, old_value, new_value) # Copy to tempfiles before diffing # TODO don't copy things that are already in files! Or find an in-memory diff algorithm - begin - new_tempfile = Tempfile.new("new") - new_tempfile.write(new_value) - new_tempfile.close - begin - old_tempfile = Tempfile.new("old") - old_tempfile.write(old_value) - old_tempfile.close + new_tempfile = Tempfile.new("new") + new_tempfile.write(new_value) + new_tempfile.close - result = Chef::Util::Diff.new.udiff(old_tempfile.path, new_tempfile.path) - result = result.gsub(/^--- #{old_tempfile.path}/, "--- #{old_path}") - result = result.gsub(/^\+\+\+ #{new_tempfile.path}/, "+++ #{new_path}") - result - ensure - old_tempfile.close! - end + begin + old_tempfile = Tempfile.new("old") + old_tempfile.write(old_value) + old_tempfile.close + + result = Chef::Util::Diff.new.udiff(old_tempfile.path, new_tempfile.path) + result = result.gsub(/^--- #{old_tempfile.path}/, "--- #{old_path}") + result = result.gsub(/^\+\+\+ #{new_tempfile.path}/, "+++ #{new_path}") + result ensure - new_tempfile.close! + old_tempfile.close! end + ensure + new_tempfile.close! end end end |