Skip to content

Remove fsnotify library dependency, using kqueue (macOS only)#6

Open
vegarsti wants to merge 1 commit intomainfrom
kqueue-only
Open

Remove fsnotify library dependency, using kqueue (macOS only)#6
vegarsti wants to merge 1 commit intomainfrom
kqueue-only

Conversation

@vegarsti
Copy link
Owner

@vegarsti vegarsti commented Feb 6, 2026

See kqueue man pages: https://man.freebsd.org/cgi/man.cgi?kqueue

  • Remove dependency on fsnotify
  • Implement kqueueWatcher using golang.org/x/sys/unix
  • Use O_EVTONLY for files (better handling of atomic saves)
  • Use NOTE_WRITE for directories (detect file creation/deletion)
  • Set FD_CLOEXEC on all file descriptors to prevent inheritance by child processes
  • Watch both files and directories depending on context

@vegarsti vegarsti changed the title Kqueue only Replace fsnotify with native kqueue implementation Feb 7, 2026
@vegarsti vegarsti changed the title Replace fsnotify with native kqueue implementation Replace fsnotify with kqueue (macOS only) Feb 7, 2026
@vegarsti vegarsti changed the title Replace fsnotify with kqueue (macOS only) Remove fsnotify library dependency, using kqueue (macOS only) Feb 7, 2026
main.go Outdated
Comment on lines +57 to +66
// Check if path is a directory
info, err := os.Stat(path)
if err != nil {
return err
}

var fd int
var fflags uint32

if info.IsDir() {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit cumbersome

- Remove dependency on github.com/fsnotify/fsnotify
- Implement kqueueWatcher using golang.org/x/sys/unix
- Use O_EVTONLY for files (better handling of atomic saves)
- Use NOTE_WRITE for directories (detect file creation/deletion)
- Set FD_CLOEXEC on all file descriptors to prevent inheritance by child processes
- Watch both files and directories depending on context
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.

1 participant