find: share output files across actions - #846
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a find output corruption bug when multiple output actions (e.g., -fprintf and -fprint0) target the same output file by ensuring those actions share a single underlying file cursor rather than independently truncating/overwriting the file.
Changes:
- Thread an
output_filesmap through matcher-tree construction to open/truncate each output path only once and reuse cloned handles. - Update
-fprint,-fprintf,-fprint0, and-flsto use the shared output-file handle logic. - Add an integration regression test that combines
-fprintfand-fprint0writing to the same output file and asserts correct concatenated output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/find/matchers/mod.rs |
Cache output File handles by path during matcher construction and return cloned handles that share the same cursor across output actions. |
tests/test_find.rs |
Add regression coverage verifying -fprintf and -fprint0 can safely share the same output file without truncation/overwrites. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #846 +/- ##
==========================================
+ Coverage 92.27% 92.29% +0.01%
==========================================
Files 35 35
Lines 7435 7447 +12
Branches 386 387 +1
==========================================
+ Hits 6861 6873 +12
Misses 433 433
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 14.66%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | printf |
31.6 ms | 37.1 ms | -14.66% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ruidosujeira:fix/777-shared-output-file (104a111) with main (f5f0f64)
Fixes #777.
Summary
-fprint,-fprintf,-fprint0, and-flsshare the same file cursor.-fprintfand-fprint0with the same output file.Testing
cargo test --lib --test test_findcargo fmt --all -- --checkAll 234 unit tests and 71
findintegration tests pass.