find: share one file handle per output path (fixes #439) - #828
Open
MsfPablo wants to merge 3 commits into
Open
Conversation
|
Commit 2081a60 has test result changes: bfs testsuite: |
Contributor
|
many jobs are failing |
Contributor
|
could you please fix the conflict? thanks |
added 2 commits
August 19, 2026 14:09
GNU find de-duplicates the files opened by -fprint, -fprintf, -fprint0 and -fls, so `find -fprint foo -fprint foo` writes each line twice. We opened a separate File per predicate, so the two handles had independent file offsets and their writes overwrote each other. Cache opened output files by the path given on the command line and hand out a shared Rc<File>, so repeated references to the same path reuse a single file offset. Fixes uutils#439
MsfPablo
force-pushed
the
fix-439-dedup-output-files
branch
from
August 19, 2026 12:10
2081a60 to
2289f66
Compare
|
Commit 2289f66 has test result changes: bfs testsuite: |
Printer::new takes Option<Rc<File>> since the output-file dedup change, but the prints_error_message test still passed a bare File. Wrap it with Rc::new to satisfy the signature and clippy -D warnings.
|
Commit 2b5c84f has test result changes: GNU findutils testsuite: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #828 +/- ##
==========================================
+ Coverage 92.22% 92.26% +0.03%
==========================================
Files 35 35
Lines 7435 7471 +36
Branches 386 387 +1
==========================================
+ Hits 6857 6893 +36
Misses 437 437
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #439.
Problem
GNU
findde-duplicates the files opened by its output predicates, sofind . -fprint foo -fprint foowrites each path tofootwice. uutilsopened a separate
Filefor every occurrence of-fprint/-fprintf/-fprint0/-fls, so each handle had its own file offset and the writesoverwrote one another — only one line per entry survived.
Fix
get_or_create_filenow caches opened output files onConfig, keyed by thepath as written on the command line (matching GNU's literal-filename
de-duplication), and hands out a shared
Rc<File>. Repeated references to thesame path therefore share a single file descriptor and a single file offset.
Printer,PrintfandLstakeOption<Rc<File>>instead ofOption<File>.The first reference still truncates, as before.
Tests
Two unit tests in
src/find/matchers/mod.rs:get_or_create_file_reuses_handle_for_same_path— the same path yields thesame
Rc, and writes through both handles append rather than overwrite.two_fprints_to_the_same_file_do_not_overwrite_each_other— end-to-endthrough
build_top_level_matcherwith-fprint out -fprint out, assertingthe entry appears twice.
Verified the regression test fails without the fix (reverting just the cache
lookup gives
left: "…abbbc\n…abbbc\n"/right: "…abbbc\n").AI disclosure
This change was written with the assistance of Claude (Anthropic). I have
reviewed the diff, and ran the build, the full test suite, clippy and rustfmt
locally as shown above.