Skip to content

head: continue after per-file read error#12308

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

head: continue after per-file read error#12308
rossilor95 wants to merge 4 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/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 15, 2026

Merging this PR will not alter performance

✅ 319 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing rossilor95:head-continue-after-read-error (cedac04) with main (2a8ce67)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on main (f28d828) during the generation of this report, so 2a8ce67 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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

@xtqqczze
Copy link
Copy Markdown
Contributor

xtqqczze commented May 18, 2026

@rossilor95
Copy link
Copy Markdown
Contributor Author

I think the test_mkfifo failures are unrelated to this PR. Can someone confirm? I see the same failure in this PR too

@xtqqczze

This comment was marked as outdated.

@xtqqczze

This comment was marked as resolved.

@rossilor95
Copy link
Copy Markdown
Contributor Author

rossilor95 commented May 19, 2026

@rossilor95 at this point, you might want to rebase...

Done!

@rossilor95 rossilor95 force-pushed the head-continue-after-read-error branch from 87ab964 to cedac04 Compare May 19, 2026 13:16
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