Skip to content

find: compare selected timestamps for -newerXY - #886

Open
SichenLiang wants to merge 1 commit into
uutils:mainfrom
SichenLiang:find-newerxy-timestamps
Open

SichenLiang wants to merge 1 commit into
uutils:mainfrom
SichenLiang:find-newerxy-timestamps

Conversation

@SichenLiang

@SichenLiang SichenLiang commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

-newerXY always used the reference mtime regardless of Y, and required both the candidate's X and Y timestamps to be newer than it. Compare the candidate's X timestamp directly with the reference's Y timestamp instead.

This fixes -anewer and -cnewer when the candidate's mtime is older but the selected timestamp is newer.

Reference symlinks now follow the active dereference mode: -P uses the link timestamp, while -H and -L use the target timestamp, or the link's own timestamp if the target does not exist. Because -follow takes effect where it appears in the expression, it changes reference handling only for later predicates. This matches the GNU find documentation.

On Windows, Y=c was rejected during parsing with -newermc: change times are not available on this platform and status 1, because the reference's change time is unavailable.

Fixes #885

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.59%. Comparing base (14e915e) to head (e6d58a0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #886      +/-   ##
==========================================
+ Coverage   92.52%   92.59%   +0.07%     
==========================================
  Files          36       36              
  Lines        7694     7686       -8     
  Branches      391      390       -1     
==========================================
- Hits         7119     7117       -2     
+ Misses        437      431       -6     
  Partials      138      138              

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

@codspeed

codspeed Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 15 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 20 untouched benchmarks


Comparing SichenLiang:find-newerxy-timestamps (e6d58a0) with main (14e915e)

Open in CodSpeed

Comment thread src/find/matchers/time.rs

/// This matcher checks whether the file is newer than the file time of any combination of
/// two comparison types from the target file's `NewerOptionType`.
/// Compare a candidate's X time with a reference file's Y time.

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.

NewerMatcher is now the same thing as this with m/m.
could we drop it and route -newer here too?

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.

Done, -newer now uses the -newerXY matcher with m/m, and NewerMatcher is removed.
Output and status are unchanged. The only visible difference is the per-file error when a directory cannot be read: “modification time” is now “Modified time”.

Comment thread src/find/matchers/time.rs
x_option,
y_option,
given_modification_time: metadata.modified()?,
reference_time: y_option.get_file_time(&metadata)?,

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.

on Windows with Y=c, the user only gets "find: unsupported".
could you please return a clearer error here?

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.

It now fails during parsing with -newermc: change times are not available on this platform, following the wording already used for -inum and -links.

Comment thread src/find/matchers/time.rs Outdated
eprintln!("skipping {x_option}/{y_option}: birth time unsupported");
continue;
};
let expected = if ["a", "m"].contains(&x_option) && ["a", "m"].contains(&y_option) {

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.

i don't get this special case, x_time > y_time gives the same result for a/m, no?
also the expected value is just the implementation copied again, so it doesn't test much

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.

ah ur right, x_time > y_time already handles I removed the special case. The test is now a table of fixed timestamps with the expected result written out for each pair.

Comment thread src/find/matchers/time.rs Outdated
}

#[test]
fn newer_option_uses_reference_birth_time_when_available() {

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.

this test is long and has two skip paths.
the integration tests already cover this, do we need it?

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.

Those tests don't cover this on Linux, since B is never used as Y there. I added one a/B row to the table and dropped the longer separate test.

`-newerXY` compared both the candidate's X and Y timestamps with the
reference file's mtime. Read the reference's Y timestamp instead, then
compare only the candidate's X timestamp with it.
This fixes `-newerXY` when Y is not `m`. It also fixes `-anewer` and
`-cnewer` when the candidate's mtime is older than the reference's.
`-newer` is the m/m case, so it now uses the same matcher and
`NewerMatcher` is removed.
Reference symlinks follow the active `-P`, `-H` or `-L` setting. `-P`
uses the link's own timestamps, while `-H` and `-L` use the target when
it exists. A later `-follow` affects only predicates that come after it.
Windows has no change time for the reference, so predicates with `Y=c`
fail during parsing with “change times are not available on this
platform”.
@SichenLiang
SichenLiang force-pushed the find-newerxy-timestamps branch from 6d34680 to e6d58a0 Compare October 10, 2026 19:17
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: -cnewer rejects a newer ctime when the mtime is older

2 participants