Merge pull request #6563 from mitchellh/sethvargo/subprocess_local_exec
Use subprocess as a poor-man's exec for local-exec
This commit is contained in:
commit
7c0f488f56
|
@ -39,8 +39,33 @@ module VagrantPlugins
|
|||
|
||||
# Execute the script, raising an exception if it fails.
|
||||
def execute!(*cmd)
|
||||
if Vagrant::Util::Platform.windows?
|
||||
execute_subprocess!(*cmd)
|
||||
else
|
||||
execute_exec!(*cmd)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Run the command as exec (unix).
|
||||
def execute_exec!(*cmd)
|
||||
Vagrant::Util::SafeExec.exec(cmd[0], *cmd[1..-1])
|
||||
end
|
||||
|
||||
# Run the command as a subprocess (windows).
|
||||
def execute_subprocess!(*cmd)
|
||||
cmd = cmd.dup << { notify: [:stdout, :stderr] }
|
||||
result = Vagrant::Util::Subprocess.execute(*cmd) do |type, data|
|
||||
if type == :stdout
|
||||
@env.ui.info(data, new_line: false)
|
||||
elsif type == :stderr
|
||||
@env.ui.warn(data, new_line: false)
|
||||
end
|
||||
end
|
||||
|
||||
Kernel.exit(result.exit_code)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -93,9 +93,19 @@ describe VagrantPlugins::LocalExecPush::Push do
|
|||
end
|
||||
|
||||
describe "#execute!" do
|
||||
it "safe execs" do
|
||||
it "uses exec on unix" do
|
||||
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
|
||||
expect(Vagrant::Util::SafeExec).to receive(:exec)
|
||||
expect { subject.execute! }.to_not raise_error
|
||||
end
|
||||
|
||||
it "uses subprocess on windows" do
|
||||
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true)
|
||||
result = double("result", exit_code: 0)
|
||||
expect(Vagrant::Util::Subprocess).to receive(:execute).and_return(result)
|
||||
expect { subject.execute! }.to raise_error { |e|
|
||||
expect(e).to be_a(SystemExit)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue