Repository navigation
tail: fix panic on header write error - #12279
Conversation
|
GNU testsuite comparison: |
b9d2a4a to
014cb8d
Compare
|
Accidentally force-pushed the wrong commit onto the PR branch for a few minutes. I’ve restored the branch to the correct state now, sorry about the noise. |
Merging this PR will degrade performance by 19.55%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
| if self.verbose { | ||
| println!( | ||
| "{}==> {string} <==", | ||
| let header_string = format!( |
There was a problem hiding this comment.
why format! + write_all + flush? writeln!(stdout().lock(), ...)? should be enough, and it would avoid the allocation (codspeed shows a memory regression)
| let mut stdout = stdout.lock(); | ||
|
|
||
| stdout.write_all(header_string.as_bytes())?; | ||
| stdout.flush()?; |
There was a problem hiding this comment.
do we need this flush? stdout is line buffered anyway
| #[cfg(target_os = "linux")] | ||
| #[test] | ||
| fn test_multiple_input_files_failed_write_is_reported() { | ||
| new_ucmd!() |
There was a problem hiding this comment.
please don't depend on /etc/hosts, create two files with at.write() instead
b9d2a4a to
34bb076
Compare
|
Hi @sylvestre! I've updated the PR and addressed your review comments:
The changes are pushed, and CI is green. Thanks for the review! |
|
Thanks for your PR |
Fixes #11993
Problem
When running tail on multiple files and redirecting output to a full device (e.g. /dev/full), uutils panics instead of exiting gracefully:
Instead of the correct GNU behavior:
Cause
HeaderPrinter::printusedprintln!to write the==> file <==headers to stdout.println!panics on write failure rather than returning a Result, so any write error (such as ENOSPC from/dev/full) caused an unhandled panic instead of a clean error message.Fix
Replaced
println!in HeaderPrinter withwrite_allandflushon a locked stdout, both of which returnio::Result. The methods now returnio::Resultand propagate write errors upstream instead of panicking.