Skip to content

FileWatchService: directory baselines off the UI thread, scans stop early (#1303) - #1306

Merged
buggins merged 1 commit into
masterfrom
dir-baseline-1303
Nov 28, 2026
Merged

buggins merged 1 commit into
masterfrom
dir-baseline-1303

Conversation

@buggins

@buggins buggins commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Fixes #1303.

Changes

  • watchDirectory() no longer reads the listing on the UI thread. The next scan (the watcher thread, or the next poll() in manual mode) adopts its listing as the subscription's baseline and reports nothing for it; changes made before that scan aren't reported (documented). A subscriber joining a shared directory watch gets its baseline the same way.
  • Found in the review: only subscriptions created before a scan started are adopted by it (scan generations), so one created while the listing is read waits for the next scan instead of getting an older listing.
  • Stopping the watcher thread (shutdown, window/platform teardown, switching to manual mode) ends a scan in progress: each WatcherThread has its own abort flag (found in the review: no service-wide flag to set and reset), checked between watched paths and between directory entries, also while a directory's entries are collected. A partial listing is neither compared nor adopted.

Testing

  • New unittest: subscribing reads no listing; a change before the first scan isn't reported; joining a shared watch; an aborted scan (before the first path, and inside scanDirectory's walk) reports and adopts nothing; a subscription created during a scan is adopted by the next one; readListing stops when told to; switching to manual mode stops the thread and polls still work. Mutation checks: the baseline adoption, the generation check, the walk's abort check and scanDirectory's early return each fail the tests when removed.
  • dub test with LDC 1.36 (37 modules), DMD 2.100.2 (37), -c console (34), dip1000, Windows (38); D-Scanner.

🤖 Generated with Claude Code

…arly (#1303)

- watchDirectory() no longer lists the directory: the next scan (watcher
  thread, or the next poll()) adopts its listing as the subscription's
  baseline, only for subscriptions created before that scan started
  (scan generations); also when joining a shared watch.
- Stopping the watcher thread ends a scan in progress: each thread has its
  own abort flag, checked between watched paths and between directory
  entries, also while a directory's entries are collected; a partial
  listing is neither compared nor adopted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@buggins buggins self-assigned this Nov 28, 2026
@buggins
buggins marked this pull request as ready for review November 28, 2026 22:06
@buggins
buggins merged commit eba65af into master Nov 28, 2026
13 checks passed
@buggins
buggins deleted the dir-baseline-1303 branch November 28, 2026 22:07
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.

FileWatchService: read directory baselines off the UI thread, stop scans early

1 participant