summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-05-03 14:26:01 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-05-03 14:26:01 -0700
commite6c646abcf314f94bce62703c3195ca183b68bc7 (patch)
treef5ef2f9ba4ad48b56b5bdaa260b031fc2dd3698e
parent58db2c3f47e86d539d21f9365adb135726719e38 (diff)
downloadchef-lcg/knife-diff-exceptions.tar.gz
fix knife diff exceptionslcg/knife-diff-exceptions
closes #4189 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/chef_fs/command_line.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb
index 5f449bad04..a61c68ceda 100644
--- a/lib/chef/chef_fs/command_line.rb
+++ b/lib/chef/chef_fs/command_line.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2012-2016, Chef Software Inc.
+# Copyright:: Copyright 2012-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -271,19 +271,18 @@ class Chef
new_tempfile.write(new_value)
new_tempfile.close
- begin
- old_tempfile = Tempfile.new("old")
- old_tempfile.write(old_value)
- old_tempfile.close
+ 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
- old_tempfile.close!
- end
+ 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
+ rescue => e
+ "!!! Unable to diff #{old_path} and #{new_path} due to #{e}"
ensure
+ old_tempfile.close!
new_tempfile.close!
end
end