Skip to content

find: warn on -name/-path patterns with a directory separator - #845

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix/name-path-separator-warning-783
Open

find: warn on -name/-path patterns with a directory separator#845
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix/name-path-separator-warning-783

Conversation

@MsfPablo

Copy link
Copy Markdown
Contributor

Closes #783.

GNU find emits a warning when:

  • a -name/-iname pattern contains a /-name matches basenames only, so such a pattern can never match and the user likely meant -wholename;
  • a -path/-ipath/-wholename/-iwholename pattern ends with / — a trailing separator can never match a real path.

This PR makes find emit the same warnings on stderr while still exiting successfully.

$ find -name a/b
find: warning: '-name' matches against basenames only, but the given pattern contains a directory separator ('/'), thus the expression will evaluate to false all the time.  Did you mean '-wholename'?
$ find -path a/
find: warning: -path a/ will not match anything because it ends with /.

All-slash exemption: a pattern made up only of / (e.g. -name / or -path /) is left alone — / is a valid basename for the root entry, so warning would be a false alarm. GNU itself miscategorises this case (GNU bug #62227); the existing find_slashes test encodes the correct behaviour and continues to pass.

Tests: four new regression tests in tests/test_find.rs cover the warning cases (name_pattern_with_separator_warns, path_pattern_ending_with_separator_warns), the no-warning positive case (name_pattern_without_separator_does_not_warn), and the all-slash exemption (all_slash_pattern_does_not_warn). cargo clippy -p findutils --tests -- -D warnings and cargo fmt --check are clean; the full test_find suite passes (73 passed, 0 failed).

GNU find emits a warning when a -name/-iname pattern contains a '/'
(it matches basenames only, so the pattern can never match and the user
likely meant -wholename) and when a -path/-wholename pattern ends with '/'
(a trailing separator can never match a real path). find now emits the same
warnings on stderr while still exiting successfully.

A pattern made up only of '/' (e.g. `-name /` or `-path /`) is exempt:
'/' is a valid basename for the root entry, so warning would be a false
alarm. GNU itself miscategorises this case (bug #62227); the existing
find_slashes test encodes the correct behaviour and is preserved.

Closes uutils#783
Comment thread src/find/matchers/mod.rs
return Err(From::from(format!("missing argument to {}", args[i])));
}
i += 1;
// GNU find warns when a -name/-iname pattern contains a directory

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does it really need a 6 lines comment ? please make it shorter

@codspeed-hq

codspeed-hq Bot commented Aug 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing MsfPablo:fix/name-path-separator-warning-783 (e00bd34) with main (1acf40a)

Open in CodSpeed

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.28%. Comparing base (1acf40a) to head (e00bd34).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #845      +/-   ##
==========================================
+ Coverage   92.22%   92.28%   +0.05%     
==========================================
  Files          35       35              
  Lines        7435     7452      +17     
  Branches      386      386              
==========================================
+ Hits         6857     6877      +20     
+ Misses        437      433       -4     
- Partials      141      142       +1     

☔ 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.

@github-actions

Copy link
Copy Markdown

Commit e00bd34 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 274 / FAILED: 37 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

Changes from main branch:
  TOTAL: +3
  PASSED: +8
  FAILED: -5

Test improvements (5):
  + gnu/execdir_path_dot
  + gnu/execdir_path_empty
  + gnu/execdir_path_relative
  + gnu/files0_from_ok
  + gnu/okdir_path_empty

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.

bug(find): do not warn when appending / to -name in the start or the end

2 participants