fix(fs.watch): emit 'change' events for files in watched directories on Linux#26009
Conversation
…on Linux Fixes #3657 When watching a directory with `fs.watch`, files created after the watch was established would only emit a 'rename' event on creation, but subsequent modifications would not emit 'change' events. The root cause was twofold: 1. `watch_dir_mask` in INotifyWatcher.zig was missing `IN.MODIFY`, so the inotify system call was not subscribed to file modification events for watched directories. 2. When directory events were processed in path_watcher.zig, all events were hardcoded to emit 'rename' instead of properly distinguishing between file creation/deletion ('rename') and file modification ('change'). This fix: - Adds `IN.MODIFY` to `watch_dir_mask` to receive modification events - Adds a `create` flag to `WatchEvent.Op` to track `IN.CREATE` events - Updates directory event processing to emit 'change' for pure write events and 'rename' for create/delete/move events Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Updated 9:18 AM PT - Jan 12th, 2026
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 26009That installs a local version of the PR into your bun-26009 --bun |
WalkthroughChanges to the file watching system introduce a Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (6)**/*.zig📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.zig📄 CodeRabbit inference engine (src/CLAUDE.md)
Files:
**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/regression/issue/*.test.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}📄 CodeRabbit inference engine (test/CLAUDE.md)
Files:
🧠 Learnings (16)📚 Learning: 2025-10-17T20:50:58.644ZApplied to files:
📚 Learning: 2026-01-05T16:32:07.551ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2026-01-05T23:04:01.518ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2026-01-05T23:04:01.518ZApplied to files:
📚 Learning: 2025-10-26T01:32:04.844ZApplied to files:
📚 Learning: 2026-01-05T23:04:01.518ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-10-19T02:44:46.354ZApplied to files:
🧬 Code graph analysis (1)test/regression/issue/3657.test.ts (2)
🔇 Additional comments (7)
Comment |
Summary
fs.watch#3657 -fs.watchon directory doesn't emitchangeevents for files created after watch startsWhen watching a directory with
fs.watch, files created after the watch was established would only emit a 'rename' event on creation, but subsequent modifications would not emit 'change' events.Root Cause
The issue was twofold:
watch_dir_maskin INotifyWatcher.zig was missingIN.MODIFY, so the inotify system call was not subscribed to file modification events for watched directories.Changes
IN.MODIFYtowatch_dir_maskto receive modification eventscreateflag toWatchEvent.Opto trackIN.CREATEeventsTest plan
test/regression/issue/3657.test.ts🤖 Generated with Claude Code