cmp, diffutils: handle stdout write errors without panicking (#165) #442
the write error is printed but we still exit 0 via second_arg_error, no?
should be 2 like cmp/diff
this keeps the "(os error 28)" suffix, cmp and diff strip it
could you please reuse format_failure_to_read_input_file?
please use std::io::Write; instead of the fully qualified calls
too weak, please check the exit code and the stderr message
returning an empty string for broken pipe and testing is_empty() in two places is fragile
could be a dedicated error variant, no?
params.executable is already an OsString, why take &OsStr and convert back?
Fixed, usage write errors now exit 2.
Reused format_failure_to_read_input_file, the suffix is gone.
Done, it now uses use std::io::Write.
The test now checks for exit 2 and the stderr message.
Replaced the empty string with a CmpError::BrokenPipe variant.
It now takes &OsString.
sylvestre
yunusarda-sudo
When writing to a full or unbuffered stdout device (such as
/dev/full),cmpand the multicall binarydiffutilspanicked inside Rust'sprintln!macro withfailed printing to stdout: No space left on device (os error 28)(exit status 134).Changes
src/cmp.rs: Write differences and verbose output directly to the locked stdout writer, reporting write errors ascmp: standard output: <error>with exit status 2 (matching GNU cmp anddiff).cmp --helpwithout panicking.src/main.rs: Safely write usage text without panicking when stdout is full.tests/by-util/test_cmp.rsfor default cmp, verbose cmp (-l), help output, and the multicall binary.Fixes #165