From 217abd3229a435b91e073fddcf743c71ae954f1e Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 13 Sep 2024 14:47:00 +0200 Subject: [PATCH] Avoid Dir.chdir by passing cwd to execute() The use of chdir is problematic in threaded environments (only one thread may chdir) and Puppet has a native method for this. Link: https://github.com/puppetlabs/puppet/pull/9387 --- lib/puppet_x/bodeco/archive.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/puppet_x/bodeco/archive.rb b/lib/puppet_x/bodeco/archive.rb index d163ca0..7d414ae 100644 --- a/lib/puppet_x/bodeco/archive.rb +++ b/lib/puppet_x/bodeco/archive.rb @@ -43,19 +43,17 @@ def extract(path = root_dir, opts = {}) custom_command = opts.fetch(:custom_command, nil) options = opts.fetch(:options) - Dir.chdir(path) do - cmd = if custom_command&.include?('%s') - custom_command % @file_path - elsif custom_command - "#{custom_command} #{options} #{@file_path}" - else - command(options) - end + cmd = if custom_command&.include?('%s') + custom_command % @file_path + elsif custom_command + "#{custom_command} #{options} #{@file_path}" + else + command(options) + end - Puppet.debug("Archive extracting #{@file} in #{path}: #{cmd}") - File.chmod(0o644, @file) if opts[:uid] || opts[:gid] - Puppet::Util::Execution.execute(cmd, uid: opts[:uid], gid: opts[:gid], failonfail: true, squelch: false, combine: true) - end + Puppet.debug("Archive extracting #{@file} in #{path}: #{cmd}") + File.chmod(0o644, @file) if opts[:uid] || opts[:gid] + Puppet::Util::Execution.execute(cmd, uid: opts[:uid], gid: opts[:gid], cwd: path, failonfail: true, squelch: false, combine: true) end private