Skip to content

Commit 217abd3

Browse files
committed
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: puppetlabs/puppet#9387
1 parent c5c0886 commit 217abd3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/puppet_x/bodeco/archive.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,17 @@ def extract(path = root_dir, opts = {})
4343

4444
custom_command = opts.fetch(:custom_command, nil)
4545
options = opts.fetch(:options)
46-
Dir.chdir(path) do
47-
cmd = if custom_command&.include?('%s')
48-
custom_command % @file_path
49-
elsif custom_command
50-
"#{custom_command} #{options} #{@file_path}"
51-
else
52-
command(options)
53-
end
46+
cmd = if custom_command&.include?('%s')
47+
custom_command % @file_path
48+
elsif custom_command
49+
"#{custom_command} #{options} #{@file_path}"
50+
else
51+
command(options)
52+
end
5453

55-
Puppet.debug("Archive extracting #{@file} in #{path}: #{cmd}")
56-
File.chmod(0o644, @file) if opts[:uid] || opts[:gid]
57-
Puppet::Util::Execution.execute(cmd, uid: opts[:uid], gid: opts[:gid], failonfail: true, squelch: false, combine: true)
58-
end
54+
Puppet.debug("Archive extracting #{@file} in #{path}: #{cmd}")
55+
File.chmod(0o644, @file) if opts[:uid] || opts[:gid]
56+
Puppet::Util::Execution.execute(cmd, uid: opts[:uid], gid: opts[:gid], cwd: path, failonfail: true, squelch: false, combine: true)
5957
end
6058

6159
private

0 commit comments

Comments
 (0)