Skip to content

find: -newerXt matches only strictly newer files, and keeps the sign of pre-1970 times - #914

Merged
sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:newerxt-strict-and-pre-epoch
Oct 22, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:newerxt-strict-and-pre-epoch

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

NewerTimeMatcher compares reference <= file time in milliseconds, so a file whose time equals the reference matches, and it takes the absolute value of a time before 1970, so a 1960 file counts as newer than a 1965 reference. GNU find needs the file to be strictly newer:

$ touch -d '2026-10-20 10:00:00 UTC' t/eq; touch -d '1960-06-01' t/old1960
$ TZ=UTC find t -newermt '2026-10-20 10:00:00' -name eq       GNU: (nothing)   uutils: t/eq
$ TZ=UTC find t -newermt '1965-01-01' -name old1960           GNU: (nothing)   uutils: t/old1960

The reference milliseconds are now turned into a SystemTime on either side of the epoch and compared with > against the file's SystemTime, which also drops the expect on the millisecond conversion.

New unit test newer_time_matcher_is_strict_and_signed sets the file's mtime with File::set_modified and fails without the change. cargo test: 430 passed, clippy and fmt clean. Both commands above now print the same as GNU find 4.10.0.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:25

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.59%. Comparing base (e176572) to head (20a67ee).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
+ Coverage   92.57%   92.59%   +0.01%     
==========================================
  Files          37       37              
  Lines        7746     7766      +20     
  Branches      393      394       +1     
==========================================
+ Hits         7171     7191      +20     
  Misses        435      435              
  Partials      140      140              

☔ 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 Oct 22, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 20 untouched benchmarks


Comparing jayhemnani9910:newerxt-strict-and-pre-epoch (20a67ee) with main (e176572)

Open in CodSpeed

Comment thread src/find/matchers/time.rs Outdated
let reference = if self.time >= 0 {
UNIX_EPOCH + Duration::from_millis(self.time.unsigned_abs())
} else {
UNIX_EPOCH - Duration::from_millis(self.time.unsigned_abs())

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 can still panic for extreme dates, e.g. before 1601 on Windows
could you please use checked_add / checked_sub?

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 in 20a67ee. The reference is now built with checked_add / checked_sub. If it can't be represented, a reference before 1970 counts every file as newer and one after counts none. The test now also covers i64::MIN and i64::MAX.

Comment thread src/find/matchers/time.rs Outdated
UNIX_EPOCH - Duration::from_millis(self.time.unsigned_abs())
};
// Strictly newer, like GNU find
Ok(this_time > reference)

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.

did you run the bfs / GNU testsuite on this? e.g.
bash util/build-bfs.sh gnu/newermt
bash util/build-gnu.sh (GNU source cloned from https://git.savannah.gnu.org/git/findutils.git into ../findutils.gnu)

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.

Yes, on main (e176572) and on this branch:

  • bfs --gnu: 284 pass, 35 fail, 19 skip
  • GNU findutils 4.10.0 testsuite: 426 pass, 74 fail, 2 skip

Every test has the same result on both. common/newermt, common/newermt_epoch_minus_one and tests/find/newer fail on both before they reach this code: the date parser rejects 1991-12-14T00:01, 1969-12-31T23:59:59Z and 2026-10-22 16:30:21.985325805 +0530.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 11:01

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre
sylvestre merged commit cc32b4f into uutils:main Oct 22, 2026
34 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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