summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-05-06 08:48:27 -0700
committerGitHub <noreply@github.com>2019-05-06 08:48:27 -0700
commit3cac093a91b8139fe7be8f987aa7c72c2df1af62 (patch)
tree5db698675938eb73774abe4ba5085d71cd2d405a
parent61f69e18e69e0dca6e8cffdcd7451181d874cdb3 (diff)
parente6c646abcf314f94bce62703c3195ca183b68bc7 (diff)
downloadchef-3cac093a91b8139fe7be8f987aa7c72c2df1af62.tar.gz
Merge pull request #8459 from chef/lcg/knife-diff-exceptions
fix knife diff exceptions
-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