lib/bolt/shell/bash.rb in bolt-2.6.0 vs lib/bolt/shell/bash.rb in bolt-2.7.0

- old
+ new

@@ -32,11 +32,11 @@ end end def upload(source, destination, options = {}) running_as(options[:run_as]) do - with_tempdir do |dir| + with_tmpdir do |dir| basename = File.basename(destination) tmpfile = File.join(dir.to_s, basename) conn.copy_file(source, tmpfile) # pass over file ownership if we're using run-as to be a different user dir.chown(run_as) @@ -53,11 +53,11 @@ def run_script(script, arguments, options = {}) # unpack any Sensitive data arguments = unwrap_sensitive_args(arguments) running_as(options[:run_as]) do - with_tempdir do |dir| + with_tmpdir do |dir| path = write_executable(dir.to_s, script) dir.chown(run_as) output = execute([path, *arguments], sudoable: true) Bolt::Result.for_command(target, output.stdout.string, @@ -84,11 +84,11 @@ # log the arguments with sensitive data redacted, do NOT log unwrapped_arguments logger.debug("Running '#{executable}' with #{arguments.to_json}#{interpreter_debug}") # unpack any Sensitive data arguments = unwrap_sensitive_args(arguments) - with_tempdir do |dir| + with_tmpdir do |dir| if extra_files.empty? task_dir = dir else # TODO: optimize upload of directories arguments['_installdir'] = dir.to_s @@ -232,19 +232,19 @@ message = "Could not make file '#{path}' executable: #{result.stderr.string}" raise Bolt::Node::FileError.new(message, 'CHMOD_ERROR') end end - def make_tempdir + def make_tmpdir tmpdir = @target.options.fetch('tmpdir', '/tmp') script_dir = @target.options.fetch('script-dir', SecureRandom.uuid) tmppath = File.join(tmpdir, script_dir) command = ['mkdir', '-m', 700, tmppath] result = execute(command) if result.exit_code != 0 - raise Bolt::Node::FileError.new("Could not make tempdir: #{result.stderr.string}", 'TEMPDIR_ERROR') + raise Bolt::Node::FileError.new("Could not make tmpdir: #{result.stderr.string}", 'TMPDIR_ERROR') end path = tmppath || result.stdout.string.chomp Bolt::Shell::Bash::Tmpdir.new(self, path) end @@ -254,16 +254,22 @@ conn.copy_file(file, remote_path) make_executable(remote_path) remote_path end - # A helper to create and delete a tempdir on the remote system. Yields the + # A helper to create and delete a tmpdir on the remote system. Yields the # directory name. - def with_tempdir - dir = make_tempdir + def with_tmpdir + dir = make_tmpdir yield dir ensure - dir&.delete + if dir + if target.options['cleanup'] + dir.delete + else + @logger.warn("Skipping cleanup of tmpdir #{dir}") + end + end end # In the case where a task is run with elevated privilege and needs stdin # a random string is echoed to stderr indicating that the stdin is available # for task input data because the sudo password has already either been