mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
## Summary - Fixes #3657 - `fs.watch` on directory doesn't emit `change` events for files created after watch starts 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. ## Root Cause The issue 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'). ## Changes - 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 ## Test plan - [x] Added regression test `test/regression/issue/3657.test.ts` - [x] Verified test fails with system Bun (before fix) - [x] Verified test passes with debug build (after fix) - [x] Verified manual reproduction from issue now works correctly 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
3.8 KiB
3.8 KiB