Skip to content

fix: replace {} placeholder in -exec utility name#647

Merged
sylvestre merged 2 commits into
uutils:mainfrom
mvanhorn:osc/614-fix-exec-placeholder
Jun 6, 2026
Merged

fix: replace {} placeholder in -exec utility name#647
sylvestre merged 2 commits into
uutils:mainfrom
mvanhorn:osc/614-fix-exec-placeholder

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

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:

find /usr/bin -name pwd -exec {} -P ';'
# Expected: runs /usr/bin/pwd -P
# Got: Failed to run {}: No such file or directory (os error 2)

Changes

  • src/find/matchers/exec.rs: Extracted parse_arg helper from the duplicated split logic. Changed SingleExecMatcher.executable from String to Arg so 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 check and cargo clippy (no warnings). Tested manually with cargo run --bin find -- /usr/bin -name pwd -exec {} -P \;.

Fixes #614

This contribution was developed with AI assistance (Claude Code).

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.78%. Comparing base (a65160f) to head (4675963).

Files with missing lines Patch % Lines
src/find/matchers/exec.rs 70.58% 5 Missing ⚠️
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.
📢 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.

@jmr
Copy link
Copy Markdown
Contributor

jmr commented Mar 27, 2026

What do you do with foo{}bar in the first position? According to POSIX, this is unspecified, but GNU will substitute there.

Also, probably a good idea to add some tests. Claude didn't do that automatically?

@sylvestre
Copy link
Copy Markdown
Contributor

Indeed, it needs tests

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Added a test in da847c6. On the foo{}bar question - the current implementation already handles embedded placeholders via the FileArg(parts) pattern (splits on {} and joins with the pathname), so foo{}bar in any position resolves to foo/path/to/filebar. This matches GNU find behavior.

Copy link
Copy Markdown
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, it needs to be rebased :/

mvanhorn added 2 commits June 5, 2026 22:34
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.
@mvanhorn mvanhorn force-pushed the osc/614-fix-exec-placeholder branch from da847c6 to 4675963 Compare June 6, 2026 05:35
@sylvestre sylvestre merged commit 1a77a83 into uutils:main Jun 6, 2026
19 of 21 checks passed
sylvestre added a commit that referenced this pull request Jun 6, 2026
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.
@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Jun 6, 2026

Appreciate the merge @sylvestre. Nice to have {} substitution in the utility_name position matching POSIX and GNU find now.

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 -exec {} [args...] \; fails

3 participants