Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tsc/internal/fswatch/kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tsc/internal/fswatch/kqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
Loading