summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-05-29 17:23:07 -0700
committerGitHub <noreply@github.com>2019-05-29 17:23:07 -0700
commitce0b097f9143032aa59abc6119e8432323f072a6 (patch)
treed1498796eaca76fec4f9d9f77c9e4da441cb8500
parent279e7ada623d902908c035bc66eaf7668c012634 (diff)
parentd118f8246060bed4b1a596437ee5ef7de584e293 (diff)
downloadchef-ce0b097f9143032aa59abc6119e8432323f072a6.tar.gz
Merge pull request #8612 from chef/backport_11
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