Skip to content

find: add -warn and -nowarn options - #839

Open
kevinburke wants to merge 3 commits into
uutils:mainfrom
kevinburke:find-warn-global-options
Open

find: add -warn and -nowarn options#839
kevinburke wants to merge 3 commits into
uutils:mainfrom
kevinburke:find-warn-global-options

Conversation

@kevinburke

Copy link
Copy Markdown
Contributor

GNU find distinguishes warnings about inadvisable command-line usage from errors encountered while traversing directories. These warnings do not change find's exit status. By default, GNU enables them only when standard input is a terminal and POSIXLY_CORRECT is unset; otherwise it disables them so existing scripts do not gain unsolicited diagnostics.

The -warn and -nowarn options change that state at the point where each appears. Thus -warn -type d -maxdepth 1 warns when parsing reaches -maxdepth, while placing -nowarn before -maxdepth suppresses the warning. Putting -nowarn at the end cannot retract a warning already emitted. GNU leaves the active warnings unspecified when POSIXLY_CORRECT and an explicit -warn are both present.

Global options such as -maxdepth are semantically non-positional: they affect tests before and after their location. GNU accepts a global option after a test or action, but warns that the ordering is misleading when warnings are enabled.

uutils previously rejected -warn and -nowarn as unknown predicates. Track the current warning state and most recent test or action, accept both options, and implement GNU's misplaced-global-option diagnostic for the supported global options. GNU also controls warnings for deprecated -d and slashes in -name or -iname patterns; those remain outside this change.

Add coverage for enabling the diagnostic and disabling it before the global option is parsed.

Copilot AI lite review requested due to automatic review settings August 17, 2026 02:17
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.58824% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.34%. Comparing base (2a3eac9) to head (5aef7b1).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/find/mod.rs 66.66% 1 Missing and 1 partial ⚠️
src/find/matchers/mod.rs 98.38% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #839      +/-   ##
==========================================
+ Coverage   92.15%   92.34%   +0.19%     
==========================================
  Files          35       35              
  Lines        7377     7501     +124     
  Branches      383      392       +9     
==========================================
+ Hits         6798     6927     +129     
+ Misses        438      432       -6     
- 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 5e14879 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 315 / PASSED: 267 / FAILED: 42 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

New test failures (1):
  - gnu/okdir_path_relative

Test improvements (1):
  + gnu/files0_from_ok

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing kevinburke:find-warn-global-options (5aef7b1) with main (1acf40a)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds GNU-compatible warning-mode handling to find, introducing -warn/-nowarn to toggle warnings during expression parsing and emitting a GNU-style diagnostic when a supported global option (e.g., -maxdepth) appears after a test/action.

Changes:

  • Track warning state and the most recent test/action during matcher-tree construction to support positional -warn/-nowarn.
  • Emit a “misplaced global option” warning when warnings are enabled and a global option follows a prior test/action.
  • Add an integration test covering enabling the diagnostic and disabling it before parsing the global option.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/test_find.rs Adds coverage for the warning emission and for suppressing it via -nowarn.
src/find/mod.rs Initializes default warning state based on stdin TTY + POSIXLY_CORRECT, and documents -warn/-nowarn in help text.
src/find/matchers/mod.rs Implements -warn/-nowarn, tracks last test/action, and emits the global-option ordering warning.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/find/matchers/mod.rs
Comment on lines +447 to +463
fn is_global_option(argument: &str) -> bool {
matches!(
argument,
"-d" | "-depth"
| "-files0-from"
| "-help"
| "--help"
| "-maxdepth"
| "-mindepth"
| "-mount"
| "-xdev"
| "-noleaf"
| "-sorted"
| "-version"
| "--version"
)
}
Comment thread src/find/matchers/mod.rs
Comment on lines +489 to +494
eprintln!(
"find: warning: you have specified the global option {argument} after the \
argument {previous}, but global options are not positional, i.e., {argument} \
affects tests specified before it as well as those specified after it. Please \
specify global options before other arguments."
);
Copilot AI review requested due to automatic review settings August 17, 2026 04:26
@kevinburke
kevinburke force-pushed the find-warn-global-options branch from 5e14879 to 546d204 Compare August 17, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@github-actions

Copy link
Copy Markdown

Commit 546d204 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 315 / PASSED: 267 / FAILED: 42 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

New test failures (1):
  - gnu/okdir_path_relative

Test improvements (1):
  + gnu/files0_from_ok

GNU find distinguishes warnings about inadvisable command-line usage from
errors encountered while traversing directories. These warnings do not
change find's exit status. By default, GNU enables them only when standard
input is a terminal and POSIXLY_CORRECT is unset; otherwise it disables
them so existing scripts do not gain unsolicited diagnostics.

The -warn and -nowarn options change that state at the point where each
appears. Thus `-warn -type d -maxdepth 1` warns when parsing reaches
-maxdepth, while placing -nowarn before -maxdepth suppresses the warning.
Putting -nowarn at the end cannot retract a warning already emitted. GNU
leaves the active warnings unspecified when POSIXLY_CORRECT and an explicit
-warn are both present.

Global options such as -maxdepth are semantically non-positional: they
affect tests before and after their location. GNU accepts a global option
after a test or action, but warns that the ordering is misleading when
warnings are enabled.

uutils previously rejected -warn and -nowarn as unknown predicates. Track
the current warning state and most recent test or action, accept both
options, and implement GNU's misplaced-global-option diagnostic for the
supported global options. Do not issue that diagnostic for help or version
options: they terminate parsing instead of affecting surrounding tests, so
the diagnostic's explanation would be false. GNU also controls warnings for
deprecated -d and slashes in -name or -iname patterns; those remain outside
this change.

Adding -warn also enables an external compatibility test which exposes an
unsafe interaction with -execdir and -okdir. Those actions change directory
before searching PATH for the requested executable, so a relative or empty
PATH entry can select a different program in each visited directory. Reject
non-absolute PATH entries when parsing either action.

Add coverage for enabling the diagnostic, disabling it before the global
option is parsed, excluding the terminating help and version options, and
rejecting relative PATH entries for directory-local actions.
Copilot AI review requested due to automatic review settings August 17, 2026 17:26
@kevinburke
kevinburke force-pushed the find-warn-global-options branch from 546d204 to 4f58b49 Compare August 17, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kevinburke

Copy link
Copy Markdown
Contributor Author

The latest change should have fixed the test suite issues. Github is having some problems, so not clear the automation will run correctly.

@sylvestre

Copy link
Copy Markdown
Contributor

could you please fix the conflict? thanks

Copilot AI review requested due to automatic review settings August 18, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comment thread src/find/matchers/mod.rs
Ok(file)
}

fn is_global_option(argument: &str) -> bool {

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.

what is a global option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a doc explaining what this means (it's a GNU term)

Address PR feedback asking for clarification on is_global_option.
Copilot AI review requested due to automatic review settings August 18, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/find/mod.rs:31

  • last_non_option is used to store the most recent test/action token for the misplaced-global-option warning, not the “last non-option” in the traditional CLI sense. Renaming this field (and the related helper is_testing_criterion) to reflect its actual meaning would make the warning logic easier to understand and maintain.
    no_leaf_dirs: bool,
    warnings_enabled: bool,
    last_non_option: Option<String>,

src/find/matchers/mod.rs:472

  • is_global_option omits -follow, but -follow mutates config.follow in a way that affects traversal and matchers globally (i.e., it is also non-positional in this implementation). As a result, -warn -type f -follow won’t emit the same misplaced-global-option warning that -maxdepth/-mindepth do. Consider including -follow in the global-option set (and therefore making it warnable) for consistency with the “global options are not positional” diagnostic.
fn is_global_option(argument: &str) -> bool {
    matches!(
        argument,
        "-d" | "-depth"
            | "-files0-from"

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.

3 participants