Skip to content

head: continue after per-file read error#12308

Open
rossilor95 wants to merge 10 commits into
uutils:mainfrom
rossilor95:head-continue-after-read-error
Open

head: continue after per-file read error#12308
rossilor95 wants to merge 10 commits into
uutils:mainfrom
rossilor95:head-continue-after-read-error

Conversation

@rossilor95
Copy link
Copy Markdown
Contributor

@rossilor95 rossilor95 commented May 15, 2026

Fixes #11846.

head now reports per-file read errors correctly and continues processing the remaining input files.

Previously, reading from files like /proc/self/mem could be reported as a standard output write error because io::copy mixed 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/full are 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/full reports a stdout write error instead of wrapping it as an input read error. Example:

# Before:
$ uutils-head input > /dev/full
head: error reading 'input': error writing 'standard output': No space left on device

# After:
$ uutils-head input > /dev/full
head: error writing 'standard output': No space left on device

Comment thread src/uu/head/src/head.rs Outdated
loop {
let n = match reader.read(&mut buf) {
Ok(0) => break,
Ok(n) => n,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you avoid same letter n?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and avoid one letter variable :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single letter variable is idiomatic for a variable bound by a pattern, but the outer variable should be named something like bytes_read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cp/link-heap is now passing!
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 15, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks
⏩ 358 skipped benchmarks1


Comparing rossilor95:head-continue-after-read-error (d3985cb) with main (7ea1211)

Open in CodSpeed

Footnotes

  1. 358 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.

@rossilor95
Copy link
Copy Markdown
Contributor Author

GNU testsuite comparison:

GNU test failed: tests/tail/pid-pipe. tests/tail/pid-pipe is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

I see this GNU test for pipe fails for other open PRs. I tried to have a look but I don't understand how it can be related to this change. WDYT?

@xtqqczze
Copy link
Copy Markdown
Contributor

Comment thread src/uu/head/src/head.rs Outdated

let bytes_written = io::copy(&mut reader, &mut writer).map_err(wrap_in_stdout_error)?;
let mut bytes_written = 0;
let mut buf = [0; BUF_SIZE];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has cost by 0-filling BUF_SIZE even n<BUF_SIZE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Tried to do this in a different way.

I switched to BufRead::fill_buf / consume so we read straight from the input's existing buffer and skip the per-call BUF_SIZE zero-fill.

The TakeLines adapter was only needed to feed the old Read-based loop, so I removed it together with its three unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

head: head /proc/self/men file does not show content of file

4 participants