Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Dir.chdir by passing cwd to execute() and simplify %s detection in custom_command #531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && custom_command =~ %r{%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
Loading