fix: replace {} placeholder in -exec utility name#647
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #647 +/- ##
==========================================
- Coverage 91.83% 91.78% -0.06%
==========================================
Files 31 31
Lines 6408 6413 +5
Branches 338 338
==========================================
+ Hits 5885 5886 +1
- Misses 397 401 +4
Partials 126 126 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
What do you do with Also, probably a good idea to add some tests. Claude didn't do that automatically? |
|
Indeed, it needs tests |
|
Added a test in da847c6. On the |
sylvestre
left a comment
There was a problem hiding this comment.
sorry, it needs to be rebased :/
The {} placeholder was only replaced in arguments to -exec, not in the
utility_name position itself. Running `find -exec {} \;` passed the
literal string "{}" to Command::new, causing "No such file or directory".
Extracted arg parsing into a shared `parse_arg` helper and changed the
`executable` field from String to the existing Arg enum so it undergoes
the same {} replacement as other arguments.
Fixes uutils#614
Verify that SingleExecMatcher resolves {} in arguments
when the executable is a known path. Covers the case
where -exec receives {} in argument positions.
da847c6 to
4675963
Compare
The test from #647 used {} only in an argument, so it passed on unpatched code. Rewrite it to make the matched entry the testing-commandline binary and pass {} as the utility name, so the placeholder must resolve to the entry's path and execute.
|
Appreciate the merge @sylvestre. Nice to have {} substitution in the utility_name position matching POSIX and GNU find now. |
Summary
Fixed -exec to replace {} in the utility_name position, not just in arguments. Previously
find -exec {} \;passed the literal string "{}" to Command::new.Why this matters
Per POSIX (
find -exec utility_name [argument ...] ;), a utility_name containing only "{}" should be replaced with the current pathname. GNU find and BSD find both handle this correctly. uutils find failed with "No such file or directory" because {} was never substituted in the executable field.Repro from #614:
Changes
src/find/matchers/exec.rs: Extractedparse_arghelper from the duplicated split logic. ChangedSingleExecMatcher.executablefromStringtoArgso it undergoes the same {} replacement as arguments. Updated error formatting to use the resolved executable path.Testing
All 25 existing tests pass. Verified compilation with
cargo checkandcargo clippy(no warnings). Tested manually withcargo run --bin find -- /usr/bin -name pwd -exec {} -P \;.Fixes #614
This contribution was developed with AI assistance (Claude Code).