Skip to content

fix: apply rules to contents of a folder moved into a watched folder - #78

Merged
lguichard merged 4 commits into
lab421:mainfrom
prismatic7:fix/watcher-new-subfolder
Oct 26, 2026
Merged

lguichard merged 4 commits into
lab421:mainfrom
prismatic7:fix/watcher-new-subfolder

Conversation

@prismatic7

Copy link
Copy Markdown
Contributor

Fixes #70.

Problem

Moving a folder into a watched folder left the files inside it unprocessed by automatic watching, even with the rule's scope set to All Levels. Run Now processed the same files fine.

Root cause

FSEvents only reports the folder itself when it arrives together with its contents: the files inside were created outside the watched tree, so no FileEvents entries are delivered for them. WatcherCoordinator settled the arriving folder (the whole-tree fingerprint wait already covers its contents) and then ran handle(path:) on the folder path alone — the subtree was never walked.

Fix

When a settled arrival is a directory, checkSettled now rescans its subtree via the existing handleRescanSubtree, the same path a MustScanSubDirs recovery or a deferred-descendants settle already takes. Because the arrival's includingContents snapshot only resolves once everything inside has stopped changing for a full settle interval, the entries are evaluated immediately (waitsForSettledFiles: false) — matching Run Now semantics, and giving folder moves the same mid-transfer protection file arrivals already have. The fingerprint cache keeps the rescan from re-evaluating paths whose own events also arrived, and depth limits from maxRuleDepth are respected as in Run Now.

Three-path consistency (per AGENTS.md)

  • Watcher: fixed and covered by the new test.
  • Dry Run / Run Now: untouched — both already walk the tree; no shared plan code changed.

Verification

  • swift build clean.
  • swift test: 330 tests in 28 suites, all passed (329 existing + 1 new).
  • Negative test: with WatcherCoordinator.swift stashed (old code), the new test folderArrivingWithContentsProcessesThemWithoutTheirOwnEvents fails with 4 issues; with the fix, all 8 WatcherSettlingTests pass.
  • Left to CI: real FSEvents delivery (the test injects the event the stream would report); no GUI run locally.

prismatic7 and others added 4 commits October 24, 2026 01:50
FSEvents only reports the folder itself when it arrives with its
contents: the files inside were created outside the watched tree and
never generate events of their own, so the watcher evaluated the folder
and stopped. Run Now processed the same files fine, because it walks
the tree.

When a settled arrival is a directory, rescan its subtree before
finishing. The arrival's includesContents snapshot already waited for
everything inside to stop changing, so the entries can be evaluated
immediately; the fingerprint cache keeps a rescan from re-evaluating
paths whose own events also arrived.

Fixes lab421#70
@lguichard
lguichard merged commit 24c4734 into lab421:main Oct 26, 2026
1 check passed
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.

Automatic watching does not process files inside newly added folders

2 participants