chown, chgrp: report a verbose stdout write error instead of panicking#13381
chown, chgrp: report a verbose stdout write error instead of panicking#13381leeewee wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
| fn write_verbose_line(&self, line: &str) -> i32 { | ||
| use std::io::Write; | ||
| if let Err(e) = writeln!(std::io::stdout(), "{line}") { | ||
| show_error!("write error: {}", strip_errno(&e)); |
There was a problem hiding this comment.
Please use the translate! macro, and preferably a PermsError enum, like #13397.
The shared ChownExecutor in uucore/perms.rs printed verbose lines with `println!`, which aborts (exit 134) when stdout can't be written, e.g. `chown -v OWNER missing > /dev/full`. Because the site is shared, both chown and chgrp abort. Write verbose lines through a helper that propagates the failure: on a write error it reports `write error: <reason>` to stderr and returns a non-zero code, matching GNU (exit 1). The three stdout `println!` sites (the obtain_meta-None branch and the two retained-as lines) now use it, and `print_verbose_ownership_retained_as` returns its exit code to its callers. Fixes uutils#10572
5dbb303 to
d2d44ea
Compare
|
Updated per review:
|
Merging this PR will improve performance by 7.71%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | complex_relative_date |
148 µs | 137.4 µs | +7.71% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing leeewee:perms-fix-verbose-write-error (d2d44ea) with main (2772896)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Fixes #10572
The verbose output in the shared
ChownExecutor(uucore/src/lib/features/perms.rs) was printed withprintln!, which aborts (exit 134) when stdout can't be written — e.g. output redirected to a full device. Because the site is shared, bothchownandchgrpabort, so this also covers thechgrpcase of the same bug:Verbose lines now go through a helper that propagates the write failure: on error it reports
write error: <reason>to stderr and returns a non-zero code, matching GNU (exit 1). The three stdoutprintln!sites (theobtain_meta→Nonebranch intraverse, and bothprint_verbose_ownership_retained_aslines) use it, andprint_verbose_ownership_retained_asnow returns its exit code to its callers.After:
This matches GNU (exit 1,
write error: No space left on device). Regression tests are added for bothchgrpandchown(/dev/full, Linux-gated), each exercising the trigger with only stdout on the full sink.