From af330286c58bc235e0c550a3ff2ba09b22002643 Mon Sep 17 00:00:00 2001 From: Soge Zhang Date: Sun, 17 Aug 2014 23:30:13 +0800 Subject: [PATCH] Fix Issue: Missing create events on OS X. #14 --- fsnotify_bsd.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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) } -- 2.50.1