Skip to content

Commit

Permalink
Avoid Dir.chdir by passing cwd to execute()
Browse files Browse the repository at this point in the history
The use of chdir is problematic in threaded environments (only one
thread may chdir) and Puppet has a native method for this.

Link: puppetlabs/puppet#9387
  • Loading branch information
ekohl committed Sep 13, 2024
1 parent c5c0886 commit 217abd3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/puppet_x/bodeco/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 217abd3

Please sign in to comment.