Skip to content

find: match GNU rounding for -amin/-cmin/-mmin - #841

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-amin-gnu
Open

find: match GNU rounding for -amin/-cmin/-mmin#841
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-amin-gnu

Conversation

@MsfPablo

Copy link
Copy Markdown
Contributor

Fixes #813.

-amin/-cmin/-mmin computed the age in minutes with a truncating division, so a file accessed a few seconds ago landed in bucket 0 and find -amin 1 didn't list it, while GNU does.

I checked the actual behaviour against GNU findutils 4.11 rather than guessing, and it turns out the three comparator forms don't share one rounding rule:

  • -amin n matches when (n-1)*60 <= age < n*60, i.e. an age of d seconds falls in bucket d/60 + 1
  • -amin -n matches when age < n*60
  • -amin +n matches when age >= n*60

Feeding a single age_in_minutes into ComparableValue can't express all three at once (whichever value you pick, one of the forms is off by one), so the comparison is now done against the age in seconds directly.

Verified against GNU on files aged 0/30/59/60/61/90/119/120/121/179/180/181 seconds — output is now identical for -mmin with 0, 1, 2, 3, -1, -2, +0, +1 and +2. Added a unit test pinning those boundaries; the two existing file_age_range_matcher assertions still pass unchanged.

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.17%. Comparing base (2a3eac9) to head (5a03048).

Files with missing lines Patch % Lines
src/find/matchers/time.rs 96.96% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #841      +/-   ##
==========================================
+ Coverage   92.15%   92.17%   +0.01%     
==========================================
  Files          35       35              
  Lines        7377     7408      +31     
  Branches      383      385       +2     
==========================================
+ Hits         6798     6828      +30     
  Misses        438      438              
- 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 ddd2b65 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 313 / PASSED: 265 / 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 (2):
  - common/amin
  - common/mmin

Test improvements (2):
  + gnu/files0_from_ok
  + gnu/okdir_path_empty

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing MsfPablo:fix-amin-gnu (5a03048) with main (2a3eac9)

Open in CodSpeed

@MsfPablo

MsfPablo commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

The bfs job flags common/amin and common/mmin as new failures. That is this change, and I think it is the right side of the difference — bfs and GNU disagree here, and tests/common/amin.out encodes bfs's answer.

Same tree bfs's test builds (files at -3600s, -121s, -61s, -30s, +60s, +3600s), run against GNU findutils 4.11, bfs 4.1.4, and this branch:

-1  gfind     in_one_hour in_one_minute thirty_seconds_ago
-1  bfs       in_one_hour in_one_minute thirty_seconds_ago
-1  ours      in_one_hour in_one_minute thirty_seconds_ago

1   gfind     thirty_seconds_ago
1   bfs       one_minute_ago
1   ours      thirty_seconds_ago

+1  gfind     one_hour_ago one_minute_ago two_minutes_ago
+1  bfs       one_hour_ago two_minutes_ago
+1  ours      one_hour_ago one_minute_ago two_minutes_ago

The bfs rows are exactly what common/amin.out contains, so those two tests are asserting bfs behaviour rather than GNU's. bfs buckets an age of 61s as minute 1; GNU buckets it as minute 2 and puts the 30s file in minute 1. Run GNU findutils tests passes, and the same job reports gnu/files0_from_ok and gnu/okdir_path_empty moving to pass, so the net FAILED count is unchanged.

Happy to add these two to ignore-intermittent.txt (or wherever known bfs divergences belong) if that is how you would rather record it — I did not want to touch that list unprompted.

(Reposting: my earlier comment had stray backslashes from a shell quoting slip.)

The age in minutes was computed with a truncating division, so a file
accessed a few seconds ago landed in bucket 0 and '-amin 1' missed it.
GNU puts an age of d seconds in bucket d/60 + 1, and compares '-amin -n'
and '-amin +n' against n*60 seconds directly, which is a different
off-by-one from the exact case. Compare against the age in seconds so
all three forms follow GNU.

Closes uutils#813
@github-actions

Copy link
Copy Markdown

Commit 5a03048 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 272 / FAILED: 39 / SKIPPED: 6
  Reference: TOTAL: 317 / PASSED: 274 / FAILED: 37 / SKIPPED: 6

Changes from main branch:
  TOTAL: +0
  PASSED: -2
  FAILED: +2

New test failures (2):
  - common/amin
  - common/mmin

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: find -amin 1 output differs with GNU

1 participant