Repository navigation
feat(find): add -size, -mtime, -mmin and -newer - #221
Conversation
7b03659 to
8a42977
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. I found nothing blocking: -size, -mtime, -mmin and -newer matched GNU find 4.9 in every realistic case I ran on a direct bind, and the error messages and exit codes match too.
Two non-blocking questions. Neither is caused by this PR, but both change what agents get back from the new predicates on the default setup:
- Copy binds (the default mode) reset mtimes.
copy_from_hostcreates each file throughvfs.create_file(src/vfs.rs:873), which stampsSystemTime::now()(src/vfs.rs:74). So on a copy bind, a 3-day-old file doesn't matchfind . -mtime +1, every file matches-mtime -1, and-newercompares the times the bind was made. On a direct bind the same files give GNU's answer. Should we preserve host mtimes on copy, or document this? - VFS directories report size 0 (
src/vfs.rs:605,InodeData::Dir(_) => (..., 0)). That meansfind . -size -1kandfind . -size 0also list.and every directory, which GNU doesn't do on ext4.-type favoids it. Fix it, or leave it?
The red CI rollup isn't a real failure. Run 43298099046 was cancelled by a newer run on the same SHA, and that run (43298190383) passed all 29 jobs, including CI Gate.
✅ What I verified
- Head:
8a42977, which merges cleanly onto main. - Tests:
cargo test --test shell_integration findpassed 54/54, including the 8 new tests. The fullshell_integrationsuite (1632 tests) passed 3 times in a row.find_mtime_boundaries_match_gnupassed 80 runs under parallel load. - Lint:
cargo clippy --all-targetsadds no new warnings, andcargo fmt --checkis clean. - Comparison against GNU find 4.9, direct bind:
- My own run: 29 cases, 0 differences. Sizes 0, 1, 511, 512, 513, 1023, 1024, 1025 and 1048577 bytes against 15
-sizearguments. mtimes 30 s, 59.5 s, 60.5 s, 119 s, 86399.5 s, 86400.5 s and 172801 s old, plus one 100 s in the future, against-mmin/-mtimewith0,1,-1,+0,+1,0.5,-0.5and-0. - An independent adversarial run: 45 commands, with only the overflow divergence in the appendix.
- Bad-argument messages match GNU byte for byte.
-newerwith!,-oand parentheses, with a relative reference, and with a missing reference (exit 1) all behave like GNU.
- My own run: 29 cases, 0 differences. Sizes 0, 1, 511, 512, 513, 1023, 1024, 1025 and 1048577 bytes against 15
- Copy vs direct, same host dir with
touch -d '3 days ago' old:find . -mtime +1gives nothing on a copy bind and./oldon a direct bind (GNU also gives./old).find . -size 0gives. ./emptyon a copy bind and./emptyon a direct bind (GNU:./empty). - Tests are well built. The time tests set real mtimes on a direct bind, the
samefixture proves-neweris strict, and the error tests assert the exact stderr and exit code.
Repro scripts and output are uploaded as gnu-diff.sh, gnu-diff-output.txt and adversarial-repro-output.txt.
Reading order
Read parse_age first (src/builtins/find.rs:141), since that's where GNU's off-by-one day shift lives. Then the Age arm in eval_expr (:387), then resolve_times (:160), then the find_mtime_boundaries_match_gnu test.
Appendix: non-blocking (3)
- ⚪ Overflowing numbers parse as
inf. Arguments of about 309 or more digits, like-mtime -999…9, becomeinf(find.rs:146-147,Ok(n) if valid => n).-mtime -infthen matches everything instead of failing with GNU's "invalid argument" error. No real caller writes this. If you want the fix anyway, it'sOk(n) if valid && n.is_finite() => n. - ⚪
-mtime 1e1is rejected, while GNU accepts exponent notation. Contrived. - Already known, not re-raised: on direct binds,
lstatfollows symlinks (src/vfs_kernel.rs:531→tokio::fs::metadataat:1114), so-newer <symlink>uses the target's mtime. You already called this out in the PR body as the blocker for-delete.
|
Thanks for checking the default copy-bind behavior too. I confirmed both metadata paths in the VFS code. I'm leaving them unchanged here because preserving copy timestamps or changing directory sizes would affect other commands as well as these new predicates. I added both limits to the description: use a direct bind when the query needs host mtimes, and The current revision's full CI run passed, including the required CI Gate; the red rollup is from the superseded run you identified. |
Description
findonly knew name, path, type and empty tests. Filtering by size or age failed, so agents couldn't use those common ways to narrow a file search.This adds
-size,-mtime,-mminand-newerwith GNU-style comparisons, including rounded-up size units, fractional ages and strictly newer reference times. These predicates use the metadata the kernel provides: copy binds reset file mtimes and VFS directories have size zero, so direct binds are needed for host timestamp queries and-type frestricts size queries to files. Traversal and existing actions stay unchanged, and-deleteremains separate while direct-bind symlink behavior is addressed.I compared the results against GNU find on the same directly bound files, including sizes and ages around the day and minute boundaries, and all 45 CLI probes matched. The tests set real mtimes so they don't depend on timing, and the full local Rust suite, doc tests, formatting, clippy and docs checks pass.
Related Issues
Part of #207
Documentation PR
N/A
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.