summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-15 11:24:02 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-09-15 11:24:02 -0700
commit41d99f6d8d8de416f9d5166e8e1f139ae768f134 (patch)
tree1bd1f2eccd21f396852b484e65213bef0774f1ff
parentdd024e78b150636fd9f9a7163c5d53e0942e3570 (diff)
downloadchef-41d99f6d8d8de416f9d5166e8e1f139ae768f134.tar.gz
use File.extname and Tempfile.open array arg
in order to preserve the extention of the file in the rendered tempfile. helps out with verification steps where the tempfile may be passed to a program which gets annoyed if the extension isn't correct. see https://github.com/chef/chef/issues/5324 for example Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/file_content_management/tempfile.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb
index bba4b34d82..f7d0bd315f 100644
--- a/lib/chef/file_content_management/tempfile.rb
+++ b/lib/chef/file_content_management/tempfile.rb
@@ -40,7 +40,7 @@ class Chef
tempfile_dirnames.each do |tempfile_dirname|
begin
- tf = ::Tempfile.open(tempfile_basename, tempfile_dirname)
+ tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname)
break
rescue SystemCallError => e
message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'"
@@ -63,12 +63,16 @@ class Chef
# as the arguments to Tempfile.new() consistently.
#
def tempfile_basename
- basename = ::File.basename(@new_resource.name)
+ basename = ::File.basename(@new_resource.name, File.extname(@new_resource.name))
basename.insert 0, "chef-"
basename.insert 0, "." unless Chef::Platform.windows? # dotfile if we're not on windows
basename
end
+ def tempfile_extension
+ File.extname(@new_resource.name)
+ end
+
# Returns the possible directories for the tempfile to be created in.
def tempfile_dirnames
# in why-run mode we need to create a Tempfile to compare against, which we will never