Repository navigation
find: report stdout write errors from -ls and -printf once - #905
Conversation
-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.
| /// 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) { |
There was a problem hiding this comment.
almost the same code as Printf::handle_output_error, could be dedup, no?
There was a problem hiding this comment.
Done. -ls and -printf now use the same handler for standard output.
|
|
||
| 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()) |
There was a problem hiding this comment.
-fls never uses this flag, do we need to pass it here?
There was a problem hiding this comment.
You're right. -fls stays on its file-output path; the shared flag is only used by -ls and -printf.
| 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>>, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] | ||
| fn find_ls_reports_stdout_write_error_once_for_all_ls() { |
There was a problem hiding this comment.
almost the same test twice, could be merged into one with -ls -ls, no?
There was a problem hiding this comment.
Done. The two tests are now one table-driven test covering -ls -ls, -printf, and -ls -printf.
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
`-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.
|
Commit 802542d has test result changes: bfs testsuite: |
| /// 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 { |
There was a problem hiding this comment.
-print / -print0 to stdout still exit 1 silently on /dev/full, could they use this too? fine in a follow-up
There was a problem hiding this comment.
Done in #908. -print, -print0, and the implicit print now use the same stdout error handler as -ls and -printf.
-lsdid not check writes to standard output, so redirecting it to/dev/fullprinted nothing and returned 0.-printfdid 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.-lsand-printfnow 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.-flsand-fprintfkeep their existing file-output handling.GNU find also prints a final
find: write errorline after the detailed diagnostic. This change does not add that extra line.Fixes #897