Skip to content

Commit

Permalink
(SERVER-3051) Pass cwd through to ShellUtils
Browse files Browse the repository at this point in the history
If a `cwd` option is passed in Puppet::Util::Execution.execute,
then pass it through to ShellUtils.executeCommand.
  • Loading branch information
joshcooper committed May 28, 2024
1 parent 3cba98f commit c10fcfe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "cwd is $PWD"
7 changes: 7 additions & 0 deletions spec/puppet-server-lib/puppet/jvm/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def test_execute(command, options = {})
expect(result).to match(/hello stderr/)
end

it "should set the current working directory" do
tmpdir = Dir.tmpdir
result = test_execute("./spec/fixtures/puppet-server-lib/puppet/jvm/execution_spec/echo_cwd.sh",
{:cwd => tmpdir})
expect(result).to match(/cwd is #{Regexp.escape(tmpdir)}/)
end

it "should return an instance of ProcessOutput for a command with args" do
result = test_execute(["echo", "hi"])
expect(result).to be_a Puppet::Util::Execution::ProcessOutput
Expand Down
4 changes: 4 additions & 0 deletions src/ruby/puppetserver-lib/puppet/server/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def self.execute(command, options)
exe_options.combine_stdout_stderr = true
end

if options[:cwd]
exe_options.working_directory = options[:cwd]
end

if args && !args.empty?
result = ShellUtils.executeCommand(binary, args.to_java(:string), exe_options)
else
Expand Down

0 comments on commit c10fcfe

Please sign in to comment.