diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-09-15 11:52:15 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-09-15 11:52:15 -0700 |
commit | 0b86d8b497a51401c4588e253fb957f2ccc20343 (patch) | |
tree | c8500d62d6a845c5adca71255fa57274eb0d10fe /lib/chef/file_content_management | |
parent | 41d99f6d8d8de416f9d5166e8e1f139ae768f134 (diff) | |
download | chef-0b86d8b497a51401c4588e253fb957f2ccc20343.tar.gz |
add tests and tweak code
also fixes the fact that we've been using @new_resource.name instead of
@new_resource.path all along which was never what was intended.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/file_content_management')
-rw-r--r-- | lib/chef/file_content_management/tempfile.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index f7d0bd315f..a52244b141 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -40,6 +40,7 @@ class Chef tempfile_dirnames.each do |tempfile_dirname| begin + # preserving the file extension of the target filename should be considered a public API tf = ::Tempfile.open([tempfile_basename, tempfile_extension], tempfile_dirname) break rescue SystemCallError => e @@ -63,14 +64,20 @@ class Chef # as the arguments to Tempfile.new() consistently. # def tempfile_basename - basename = ::File.basename(@new_resource.name, File.extname(@new_resource.name)) + basename = ::File.basename(@new_resource.path, tempfile_extension) + # the leading "[.]chef-" here should be considered a public API and should not be changed basename.insert 0, "chef-" basename.insert 0, "." unless Chef::Platform.windows? # dotfile if we're not on windows basename end + # this is similar to File.extname() but greedy about the extension (from the first dot, not the last dot) def tempfile_extension - File.extname(@new_resource.name) + File.basename(@new_resource.path)[/\..*/] || "" + end + + # kinda like File.extname, but greedier about the extension + def greedy_extname end # Returns the possible directories for the tempfile to be created in. |