sourcegraph/lib/process
Adam Harvey 79226578ec
lib/process: always pipe _exactly_ what the command outputs (#36574)
Right now, we use the default scanner split function, which is
`bufio.SplitLines`. This removes the trailing newline and any preceding
`\r` before it, then returns the remainder of the token. `PipeOutput`
then puts the newline back by invoking `fmt.Fprintln`.

This has the positive effect that we essentially normalise `\r\n` and
`\n` into `\n`, but the negative effect that every line of output
becomes newline-terminated, even if it's a final line that doesn't
include a newline.

This matters because this output is then used for output variables when
executing batch specs, which means that something like `echo -n hi` will
end up with an extraneous newline, even though `echo -n` has only
written two bytes to stdout.

Instead, let's set the split function to one that splits by line, but
_retains_ the newline, and then we can write it to the piped writer(s)
with `fmt.Fprint` directly.

The one tradeoff here is that I haven't reimplemented the `\r`
swallowing that `bufio.SplitLines` does. In practice, I don't believe we
ever actually used this behaviour: Docker _may_ return extraneous `\r`
bytes when running with TTY mode enabled, but we never enable that when
executing batch specs, and if the user's container actually outputs `\r`
we should actually retain it, rather than trying to filter their output.

Fixes #36562.
2022-06-03 15:13:27 -07:00
..
logger.go sg: Print output, even if it's just one character (#29745) 2022-01-14 13:24:04 +00:00
pipe_test.go lib/process: always pipe _exactly_ what the command outputs (#36574) 2022-06-03 15:13:27 -07:00
pipe.go lib/process: always pipe _exactly_ what the command outputs (#36574) 2022-06-03 15:13:27 -07:00