From a8f786961bfaa7e07fa679f8ef8b6e6631a782c8 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 3 May 2022 16:26:49 +0200 Subject: [PATCH] Use tmpfile extension Having a proper extension, even for temporary files is much cleaner. --- lib/beaker_puppet_helpers/dsl.rb | 2 +- lib/beaker_puppet_helpers/install_utils.rb | 3 +-- lib/beaker_puppet_helpers/module_utils.rb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/beaker_puppet_helpers/dsl.rb b/lib/beaker_puppet_helpers/dsl.rb index 6fcbd0b..b1aa7a6 100644 --- a/lib/beaker_puppet_helpers/dsl.rb +++ b/lib/beaker_puppet_helpers/dsl.rb @@ -167,7 +167,7 @@ def apply_manifest_on(hosts, manifest, opts = {}, &block) puppet_apply_opts = host[:default_apply_opts].merge(puppet_apply_opts) if host[:default_apply_opts].respond_to? :merge - file_path = host.tmpfile(%(apply_manifest_#{Time.now.strftime('%H%M%S%L')}.pp)) + file_path = host.tmpfile(%(apply_manifest_#{Time.now.strftime('%H%M%S%L')}), '.pp') begin create_remote_file(host, file_path, "#{manifest}\n") diff --git a/lib/beaker_puppet_helpers/install_utils.rb b/lib/beaker_puppet_helpers/install_utils.rb index 444b542..abe245c 100644 --- a/lib/beaker_puppet_helpers/install_utils.rb +++ b/lib/beaker_puppet_helpers/install_utils.rb @@ -93,8 +93,7 @@ def self.puppet_package_name(host, prefer_aio: true) def self.wget_on(host, url) extension = File.extname(url) name = File.basename(url, extension) - # Can't use host.tmpfile since we need to set an extension - target = host.exec(Beaker::Command.new("mktemp -t '#{name}-XXXXXX#{extension}'")).stdout.strip + target = host.tmpfile(name, extension) begin host.exec(Beaker::Command.new("wget -O '#{target}' '#{url}'")) yield target diff --git a/lib/beaker_puppet_helpers/module_utils.rb b/lib/beaker_puppet_helpers/module_utils.rb index f01d4f9..5f6d68d 100644 --- a/lib/beaker_puppet_helpers/module_utils.rb +++ b/lib/beaker_puppet_helpers/module_utils.rb @@ -43,7 +43,7 @@ def install_local_module_on(hosts, source = '.') source_path = builder.build begin block_on hosts do |host| - target_file = host.tmpfile('puppet_module') + target_file = host.tmpfile('puppet_module', '.tar.gz') begin host.do_scp_to(source_path, target_file, {}) install_puppet_module_via_pmt_on(host, target_file)