head: continue after per-file read error#12308
Conversation
| loop { | ||
| let n = match reader.read(&mut buf) { | ||
| Ok(0) => break, | ||
| Ok(n) => n, |
There was a problem hiding this comment.
Would you avoid same letter n?
There was a problem hiding this comment.
and avoid one letter variable :)
There was a problem hiding this comment.
A single letter variable is idiomatic for a variable bound by a pattern, but the outer variable should be named something like bytes_read.
There was a problem hiding this comment.
Hey folks, thank you for the review! I renamed the variable to bytes_read and removed the one letter inner variable (used map_err instead).
|
GNU testsuite comparison: |
Merging this PR will improve performance by 13.71%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
…ossilor95/coreutils into head-continue-after-read-error
I see this GNU test for |
Fixes #11846.
headnow reports per-file read errors correctly and continues processing the remaining input files.Previously, reading from files like
/proc/self/memcould be reported as a standard output write error becauseio::copymixed read and write failures into the same error path.This change keeps read errors associated with the input file, while preserving stdout write error handling. In particular, stdout failures such as writing a named file to
/dev/fullare still reported as standard output errors instead of being wrapped as input file read errors.Added a regression test matching GNU
tests/head/head-write-error, ensuring head input> /dev/fullreports a stdout write error instead of wrapping it as an input read error. Example: