Merge pull request #8291 from chrisroberts/enhancement/stderr-garbage
Discard initial stderr data
This commit is contained in:
commit
16c2b1ec50
|
@ -496,6 +496,8 @@ module VagrantPlugins
|
|||
|
||||
marker_found = false
|
||||
data_buffer = ''
|
||||
stderr_marker_found = false
|
||||
stderr_data_buffer = ''
|
||||
|
||||
ch.exec(shell_cmd(opts)) do |ch2, _|
|
||||
# Setup the channel callbacks so we can get data and exit status
|
||||
|
@ -512,7 +514,7 @@ module VagrantPlugins
|
|||
if marker_index
|
||||
marker_found = true
|
||||
data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
|
||||
data.replace data_buffer
|
||||
data.replace(data_buffer)
|
||||
data_buffer = nil
|
||||
end
|
||||
end
|
||||
|
@ -527,7 +529,20 @@ module VagrantPlugins
|
|||
# Filter out the clear screen command
|
||||
data = remove_ansi_escape_codes(data)
|
||||
@logger.debug("stderr: #{data}")
|
||||
yield :stderr, data if block_given?
|
||||
if !stderr_marker_found
|
||||
stderr_data_buffer << data
|
||||
marker_index = stderr_data_buffer.index(CMD_GARBAGE_MARKER)
|
||||
if marker_index
|
||||
marker_found = true
|
||||
stderr_data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
|
||||
data.replace(stderr_data_buffer)
|
||||
data_buffer = nil
|
||||
end
|
||||
end
|
||||
|
||||
if block_given? && marker_found
|
||||
yield :stderr, data
|
||||
end
|
||||
end
|
||||
|
||||
ch2.on_request("exit-status") do |ch3, data|
|
||||
|
@ -583,7 +598,7 @@ module VagrantPlugins
|
|||
data = data.force_encoding('ASCII-8BIT')
|
||||
ch2.send_data data
|
||||
else
|
||||
ch2.send_data "printf '#{CMD_GARBAGE_MARKER}'\n#{command}\n".force_encoding('ASCII-8BIT')
|
||||
ch2.send_data "printf '#{CMD_GARBAGE_MARKER}'\n(>&2 printf '#{CMD_GARBAGE_MARKER}')\n#{command}\n".force_encoding('ASCII-8BIT')
|
||||
# Remember to exit or this channel will hang open
|
||||
ch2.send_data "exit\n"
|
||||
end
|
||||
|
|
|
@ -132,7 +132,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
|||
|
||||
it "prepends UUID output to command for garbage removal" do
|
||||
expect(command_channel).to receive(:send_data).
|
||||
with("printf '#{command_garbage_marker}'\nls /\n")
|
||||
with("printf '#{command_garbage_marker}'\n(>&2 printf '#{command_garbage_marker}')\nls /\n")
|
||||
expect(communicator.execute("ls /")).to eq(0)
|
||||
end
|
||||
|
||||
|
@ -159,13 +159,33 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
|||
stdout = ''
|
||||
expect(
|
||||
communicator.execute("ls /") do |type, data|
|
||||
if type == :stdout
|
||||
stdout << data
|
||||
end
|
||||
end
|
||||
).to eq(0)
|
||||
expect(stdout).to eq("bin\ntmp\n")
|
||||
end
|
||||
end
|
||||
|
||||
context "with garbage content prepended to command stderr output" do
|
||||
let(:command_stderr_data) do
|
||||
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
|
||||
end
|
||||
|
||||
it "removes any garbage output prepended to command stderr output" do
|
||||
stderr = ''
|
||||
expect(
|
||||
communicator.execute("ls /") do |type, data|
|
||||
if type == :stderr
|
||||
stderr << data
|
||||
end
|
||||
end
|
||||
).to eq(0)
|
||||
expect(stderr).to eq("bin\ntmp\n")
|
||||
end
|
||||
end
|
||||
|
||||
context "with pty enabled" do
|
||||
before do
|
||||
expect(ssh).to receive(:pty).and_return true
|
||||
|
|
Loading…
Reference in New Issue