Skip to content

Missing create events on OS X #14

@nathany

Description

@nathany

@elgs reported this issue at howeyc/fsnotify#82

In the a directory, when I run touch a s d f g h k l, it outputs:

2014/02/02 03:31:00 event: "/Volumes/User/Home/Desktop/a/a": CREATE
2014/02/02 03:31:00 event: "/Volumes/User/Home/Desktop/a/d": CREATE
2014/02/02 03:31:00 event: "/Volumes/User/Home/Desktop/a/s": CREATE
2014/02/02 03:31:00 event: "/Volumes/User/Home/Desktop/a/l": CREATE

kqueue doesn't have a NOTE_CREATE event so fsnotify_bsd.go is doing a ReadDir and scanning for created files. However, it someone gets confused as to which files already exist:

/Users/nathany/Desktop/a/a false
/Users/nathany/Desktop/a/s false
2014/02/01 22:26:28 event: "/Users/nathany/Desktop/a/a": CREATE!
2014/02/01 22:26:28 event: "/Users/nathany/Desktop/a/s": CREATE!
/Users/nathany/Desktop/a/a true
/Users/nathany/Desktop/a/d true
/Users/nathany/Desktop/a/f true
/Users/nathany/Desktop/a/g true
/Users/nathany/Desktop/a/h true
/Users/nathany/Desktop/a/j true
/Users/nathany/Desktop/a/k true
/Users/nathany/Desktop/a/l false
/Users/nathany/Desktop/a/s true
2014/02/01 22:26:28 event: "/Users/nathany/Desktop/a/l": CREATE!

The problem is that sendDirectoryChangeEvents does a ReadDir and sends a create event for a file. Then it calls watchDirectoryFiles which does a ReadDir as well. By this time more files have been touched so ReadDir gets a different result.

watchDirectoryFiles is marking those files as existing without sending create events. And since they have been flagged as existing, those files are never sent as create events the next time sendDirectoryChangeEvents is called.

For some reason I haven't been able to reproduce the issue on FreeBSD, which uses nearly all the same code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions