]> go.fuhry.dev Git - fsnotify.git/commitdiff
Fix Issue: Missing create events on OS X. #14
authorSoge Zhang <zhssoge@gmail.com>
Sun, 17 Aug 2014 15:30:13 +0000 (23:30 +0800)
committerNathan Youngman <git@nathany.com>
Sun, 17 Aug 2014 21:22:30 +0000 (15:22 -0600)
fsnotify_bsd.go

index c43c9721cbbc28602504bf1e8bf0c9244d278444..5e02974fba26db1c6cdfcf1d3fcaed887fbc7154 100644 (file)
@@ -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)
 }