Skip to content

head: continue after per-file read error#12308

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

head: continue after per-file read error#12308
rossilor95 wants to merge 6 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:

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)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 15, 2026

Merging this PR will improve performance by 13.71%

⚡ 2 improved benchmarks
✅ 315 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory cp_recursive_deep_tree[(120, 4)] 699.2 KB 562.5 KB +24.31%
Simulation ls_recursive_balanced_tree[(6, 4, 15)] 50.9 ms 48.9 ms +4.01%

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 rossilor95:head-continue-after-read-error (dd07c80) with main (d09f351)

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.

@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

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