From: Soge Zhang Date: Sun, 17 Aug 2014 15:30:13 +0000 (+0800) Subject: Fix Issue: Missing create events on OS X. #14 X-Git-Tag: v1.7.2~276 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=af330286c58bc235e0c550a3ff2ba09b22002643;p=fsnotify.git Fix Issue: Missing create events on OS X. #14 --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index c43c972..5e02974 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -450,9 +450,28 @@ func (w *Watcher) sendDirectoryChangeEvents(dirPath string) { event := newEvent(filePath, 0, true) w.Events <- event } + + // watchDirectoryFiles (but without doing another ReadDir) + if fileInfo.IsDir() == false { + // Watch file to mimic linux fsnotify + w.addWatch(filePath, noteAllEvents) + } else { + // If the user is currently watching directory + // we want to preserve the flags used + w.enmut.Lock() + currFlags, found := w.enFlags[filePath] + w.enmut.Unlock() + var newFlags uint32 = syscall.NOTE_DELETE + if found { + newFlags |= currFlags + } + + // Linux gives deletes if not explicitly watching + w.addWatch(filePath, newFlags) + } + w.femut.Lock() w.fileExists[filePath] = true w.femut.Unlock() } - w.watchDirectoryFiles(dirPath) }