Skip to content

find: report stdout write errors from -ls and -printf once - #905

Merged
sylvestre merged 2 commits into
uutils:mainfrom
SichenLiang:ls-stdout-write-errors
Oct 17, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
SichenLiang:ls-stdout-write-errors

Conversation

@SichenLiang

@SichenLiang SichenLiang commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

-ls did not check writes to standard output, so redirecting it to /dev/full printed nothing and returned 0. -printf did report the error, but once for every entry and with an (os error 28) suffix. GNU find reports the underlying write error once and exits 1.

$ find . -maxdepth 0 -ls > /dev/full; echo $?
find: 'standard output': No space left on device
1

-ls and -printf now use the same stdout error handler. The first failed write is reported once for the whole command, and the exit status is set to 1. A broken pipe stops the walk for both. -fls and -fprintf keep their existing file-output handling.

GNU find also prints a final find: write error line after the detailed diagnostic. This change does not add that extra line.

Fixes #897

-ls ignored failed writes to standard output, so find -ls >/dev/full
printed nothing and exited 0. GNU find reports the error and exits 1.

Report the first failure as "find: 'standard output': <error>", once
per command, and set the exit status to 1. Keep the existing behavior
for a broken pipe, and leave -fls error handling unchanged.
Comment thread src/find/matchers/ls.rs Outdated
/// Handles a failed write to standard output. A broken pipe is ignored;
/// any other error is reported once, as
/// `find: 'standard output': <error>`, and makes find exit with status 1.
fn report_stdout_error(&self, error: &std::io::Error, matcher_io: &mut MatcherIO) {

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.

almost the same code as Printf::handle_output_error, could be dedup, no?

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.

Done. -ls and -printf now use the same handler for standard output.

Comment thread src/find/matchers/mod.rs Outdated

let file = get_or_create_file(args[i])?;
Some(Ls::new(Some(file)).into_box())
Some(Ls::new(Some(file), config.ls_stdout_error_reported.clone()).into_box())

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.

-fls never uses this flag, do we need to pass it here?

@SichenLiang SichenLiang Oct 15, 2026 •

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. -fls stays on its file-output path; the shared flag is only used by -ls and -printf.

Comment thread src/find/mod.rs Outdated
interactive_exec: bool,
/// Shared by every -ls, so that a failed write to standard output is
/// reported only once.
ls_stdout_error_reported: Rc<Cell<bool>>,

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.

why only -ls?
-printf to stdout has the same problem, see handle_output_error in printf.rs
could this be a generic stdout error flag shared by both?

@SichenLiang SichenLiang Oct 15, 2026 •

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.

makes sense I moved the flag to the stdout handler shared by -ls and -printf. Both now report the first stdout error once per command, and a broken pipe stops the walk for -ls just as it already did for -printf.

Comment thread tests/test_find.rs Outdated

#[test]
#[cfg(target_os = "linux")]
fn find_ls_reports_stdout_write_error_once_for_all_ls() {

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.

almost the same test twice, could be merged into one with -ls -ls, no?

@SichenLiang SichenLiang Oct 15, 2026 •

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.

Done. The two tests are now one table-driven test covering -ls -ls, -printf, and -ls -printf.

@codspeed

codspeed Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 15 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 20 untouched benchmarks


Comparing SichenLiang:ls-stdout-write-errors (802542d) with main (2b15f5d)

Open in CodSpeed

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.54%. Comparing base (2b15f5d) to head (802542d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #905      +/-   ##
==========================================
+ Coverage   92.52%   92.54%   +0.01%     
==========================================
  Files          36       36              
  Lines        7694     7727      +33     
  Branches      391      393       +2     
==========================================
+ Hits         7119     7151      +32     
+ Misses        437      436       -1     
- Partials      138      140       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

`-printf` had a separate path for stdout write errors, so a failure such
as `/dev/full` produced one diagnostic per entry and included Rust's
`(os error 28)` suffix. Send both `-ls` and `-printf` through the same
handler.

Report only the first error, set the exit status to 1, and stop walking
on a broken pipe. `-printf` already stopped on broken pipes. `-fls` and
`-fprintf` are unchanged.
@SichenLiang SichenLiang changed the title find: report -ls write errors on standard output find: report stdout write errors from -ls and -printf once Oct 15, 2026
@github-actions

Copy link
Copy Markdown

Commit 802542d has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 315 / PASSED: 272 / FAILED: 37 / SKIPPED: 6
  Reference: TOTAL: 317 / PASSED: 274 / FAILED: 37 / SKIPPED: 6

Changes from main branch:
  TOTAL: -2
  PASSED: -2
  FAILED: +0

No result in this run (2) - hung, crashed, or renamed:
  ? posix/depth_error (was PASS)
  ? posix/nouser (was PASS)

Comment thread src/find/matchers/mod.rs
/// pipe ends the walk; any other error is reported once for the whole command
/// and makes find exit with status 1.
#[derive(Clone, Default)]
pub(crate) struct StdoutErrors {

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.

-print / -print0 to stdout still exit 1 silently on /dev/full, could they use this too? fine in a follow-up

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.

Done in #908. -print, -print0, and the implicit print now use the same stdout error handler as -ls and -printf.

@sylvestre
sylvestre merged commit 531c606 into uutils:main Oct 17, 2026
34 checks passed
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.

find: -ls ignores write errors on standard output

2 participants