Skip to content

Commit 7134981

Browse files
authored
Merge pull request #531 from ekohl/fix-extract
Avoid Dir.chdir by passing cwd to execute() and simplify %s detection in custom_command
2 parents be6ddc3 + 217abd3 commit 7134981

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 && custom_command =~ %r{%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)