Repository navigation
fix(find): sample directory times before the enumeration open (#1402) - #1418
Merged
Merged
Conversation
The -used/-atime family sampled a directory's atime/ctime after the traversal had already opened it for enumeration. Under relatime-style semantics that enumeration open raises the directory atime (the Wine harness measured a root operand at atime-ctime = -5 ms before a run and +302 ms after), so a directory could match -used on the bump its own traversal caused, while GNU's fts layer stats each start point before opendir and never sees it. Capture the entry's own timestamps in one pre-open probe and feed that snapshot to every -atime/-amin/-ctime/-cmin/-mtime/-mmin/-used and -newerXY/-anewer/-cnewer evaluation for the entry, in all three traversals (scan_one_root, scan_depth_first, scan_delete_depth_first). A bitmask computed from the active predicates keeps non-time queries probe-free, and the snapshot also makes verdicts independent of evaluation order inside entry_matches (-empty enumerates the directory before the time family runs). The issue1402 regression tests drive -used against directory operands with controlled access times; on volumes with last-access updates enabled they fail on the pre-fix traversal (root drops out of -used +100, subtree directories enter -used 1) and pass with the snapshot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1402
Problem
find -used 1on a root directory operand (.) could include.itself where GNU does not. The traversal opened/enumerated a directory before sampling its atime/ctime for the-used/-atimefamily, so under relatime-style semantics the verdict was judged on the atime bump the traversal's own enumeration open had just caused. GNU findutils' fts layer stats each start point beforeopendir, which naturally avoids this. Issue evidence: a fixture where.had atime−ctime = −5.0 ms before the run (negative gaps must never match-used) still matched, and the gap measured +302 ms after the run.Fix
Sample a directory's own timestamps before any open the traversal performs on it, and feed that pre-open snapshot to every time-family evaluation for the entry:
EntryTimessnapshot captured once per entry viacapture_pre_open_times(), covering only the timestamp kinds the active predicates read (cfg.time_sample_mask, computed inbuild_configfrom the direct time filters plus an AST walkexpression_time_sample_mask()over the expression tree — non-time queries stay probe-free).entry_matches/evaluate_expressionand consumed byfile_age_seconds,file_age_daystart_seconds,used_gap_ticks, and the-newerXY/-anewer/-cnewerentry-time reads, in all three traversals:scan_depth_first/scan_delete_depth_first(-depth / -delete): captured right after the stat, before the loop-detection identity probe and the directory enumeration — previously the directory's own verdict was evaluated last, after its whole subtree had been walked.scan_one_root: captured for the starting point before the recursive iterator is constructed, and per-entry beforeentry_matchesin the iteration loop.entry_matches—-emptyenumerates the directory before the time family runs, which under relatime had the same contamination shape.i18n delta
None. No user-visible text changed (no diagnostics, help, or option text touched).
Tests
find.issue1402_root_operand_negative_used_gap_excludes_directory: a negative-gap root operand is excluded from-used +100,-used 1, and-used -1; a future-atime child directory and file still match-used +100.find.issue1402_depth_scan_samples_directory_times_before_enumeration: under-depththe directory's own verdict comes from pre-open times; default and-depthtraversals agree on the same fixture.find.issue1402_expression_time_nodes_use_pre_open_times_for_directories: the expression path (-name d -used +100) consumes the same snapshot for a directory operand.On this Windows dev box the volume has last-access updates enabled (system-managed policy on large volumes), so the regression tests were verified to fail on the pre-fix traversal — with the old order the root dropped out of
-used +100and the subtree directory entered-used 1, exactly the issue mechanism — and to pass with the snapshot. They remain meaningful pins for the Wine harness where the issue evidence was gathered.Verification
scripts/build-with-vs.ps1) clean.find.*: 156/157 pass; the single failure isfind.issue_1309_ls_suppresses_default_print_and_has_all_fields, the known environment baseline failure called out in the issue notes.xargs.xargs_interactive_*,xargs.xargs_max_chars_splits_batches,xargs.xargs_delimiter_does_not_force_exit_if_exceeded,xargs.xargs_verbose_quotes_special_args_1322,*.issue_1288_*,find.issue_1309_*): 3343 passed, 0 failed.