diff --git a/tsc/internal/fswatch/kqueue.go b/tsc/internal/fswatch/kqueue.go index 6376b1068e14b..1305e5199264a 100644 --- a/tsc/internal/fswatch/kqueue.go +++ b/tsc/internal/fswatch/kqueue.go @@ -112,6 +112,10 @@ func newKqueueIdentity[D ~int32 | ~uint32 | ~int64 | ~uint64](device D, inode ui return kqueueIdentity{device: uint64(device), inode: inode} } +// kqueueVnodeFflags lists the file and directory changes each watch reports. +const kqueueVnodeFflags = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_EXTEND | + unix.NOTE_ATTRIB | unix.NOTE_RENAME | unix.NOTE_REVOKE + // kqueueSubscription. type kqueueSubscription struct { dirWatch *dirWatch @@ -392,8 +396,7 @@ func (b *kqueueBackend) openEntryLocked(entry *dirEntry) error { } var ev unix.Kevent_t unix.SetKevent(&ev, fd, unix.EVFILT_VNODE, unix.EV_ADD|unix.EV_CLEAR|unix.EV_ENABLE) - ev.Fflags = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_EXTEND | - unix.NOTE_ATTRIB | unix.NOTE_RENAME | unix.NOTE_REVOKE + ev.Fflags = kqueueVnodeFflags if _, err := unix.Kevent(b.kq, []unix.Kevent_t{ev}, nil, nil); err != nil { unix.Close(fd) return err diff --git a/tsc/internal/fswatch/kqueue_test.go b/tsc/internal/fswatch/kqueue_test.go index a0dbbb8bd87c4..bf42e9e31b6df 100644 --- a/tsc/internal/fswatch/kqueue_test.go +++ b/tsc/internal/fswatch/kqueue_test.go @@ -298,11 +298,13 @@ func TestKqueueReplacementWatchBeforeParentDispatch(t *testing.T) { //nolint:par rootFD := kqueueTestDescriptor(t, root, int(lower.Fd())) childFD := kqueueTestDescriptor(t, child, int(lower.Fd())) - // Hold actual kernel delivery while the public API subscribes to the - // replacement. No backend subscription bookkeeping is modified. + // Pause kernel event delivery while the public API subscribes to the + // replacement. On macOS, EV_DISABLE and EV_ENABLE also set the watch's + // event mask, so both pass the backend's full mask. changes := make([]unix.Kevent_t, 2) for i, fd := range []int{rootFD, childFD} { unix.SetKevent(&changes[i], fd, unix.EVFILT_VNODE, unix.EV_DISABLE) + changes[i].Fflags = kqueueVnodeFflags } if _, err := unix.Kevent(impl.kq, changes, nil, nil); err != nil { t.Fatal(err) @@ -315,6 +317,7 @@ func TestKqueueReplacementWatchBeforeParentDispatch(t *testing.T) { //nolint:par } childRec, _ := subscribeFor(t, child, w) unix.SetKevent(&changes[0], rootFD, unix.EVFILT_VNODE, unix.EV_ENABLE) + changes[0].Fflags = kqueueVnodeFflags if _, err := unix.Kevent(impl.kq, changes[:1], nil, nil); err != nil { t.Fatal(err) }