]> go.fuhry.dev Git - fsnotify.git/commitdiff
BSD - Some internal watch flag cleanup
authorChris Howey <chris@howey.me>
Thu, 14 Mar 2013 01:31:43 +0000 (20:31 -0500)
committerChris Howey <chris@howey.me>
Thu, 14 Mar 2013 01:31:43 +0000 (20:31 -0500)
fsnotify_bsd.go

index 6d09d21dafb2dc1a7a276e5befcd3ec75c2a27d1..abbafdad7af6d7acc57100d7b965788c1854895e 100644 (file)
@@ -232,6 +232,13 @@ func (w *Watcher) removeWatch(path string) error {
        w.wmut.Lock()
        delete(w.watches, path)
        w.wmut.Unlock()
+       w.enmut.Lock()
+       delete(w.enFlags, path)
+       w.enmut.Unlock()
+       w.pmut.Lock()
+       delete(w.paths, watchfd)
+       delete(w.finfo, watchfd)
+       w.pmut.Unlock()
        return nil
 }
 
@@ -358,17 +365,18 @@ func (w *Watcher) watchDirectoryFiles(dirPath string) error {
        // Search for new files
        for _, fileInfo := range files {
                filePath := filepath.Join(dirPath, fileInfo.Name())
-               if fileInfo.IsDir() == false {
-                       // Inherit fsnFlags from parent directory
-                       w.fsnmut.Lock()
-                       dirFsnFlags, dirFsnFound := w.fsnFlags[dirPath]
-                       if dirFsnFound {
-                               w.fsnFlags[filePath] = dirFsnFlags
-                       } else {
-                               w.fsnFlags[filePath] = FSN_ALL
-                       }
-                       w.fsnmut.Unlock()
 
+               // Inherit fsnFlags from parent directory
+               w.fsnmut.Lock()
+               dirFsnFlags, dirFsnFound := w.fsnFlags[dirPath]
+               if dirFsnFound {
+                       w.fsnFlags[filePath] = dirFsnFlags
+               } else {
+                       w.fsnFlags[filePath] = FSN_ALL
+               }
+               w.fsnmut.Unlock()
+
+               if fileInfo.IsDir() == false {
                        // Watch file to mimic linux fsnotify
                        e := w.addWatch(filePath, NOTE_DELETE|NOTE_WRITE|NOTE_RENAME)
                        if e != nil {
@@ -387,9 +395,6 @@ func (w *Watcher) watchDirectoryFiles(dirPath string) error {
 
                        // Linux gives deletes if not explicitly watching
                        e := w.addWatch(filePath, newFlags)
-                       w.fsnmut.Lock()
-                       w.fsnFlags[filePath] = FSN_ALL
-                       w.fsnmut.Unlock()
                        if e != nil {
                                return e
                        }
@@ -420,9 +425,16 @@ func (w *Watcher) sendDirectoryChangeEvents(dirPath string) {
                _, doesExist := w.fileExists[filePath]
                w.femut.Unlock()
                if !doesExist {
+                       // Inherit fsnFlags from parent directory
                        w.fsnmut.Lock()
-                       w.fsnFlags[filePath] = FSN_ALL
+                       dirFsnFlags, dirFsnFound := w.fsnFlags[dirPath]
+                       if dirFsnFound {
+                               w.fsnFlags[filePath] = dirFsnFlags
+                       } else {
+                               w.fsnFlags[filePath] = FSN_ALL
+                       }
                        w.fsnmut.Unlock()
+
                        // Send create event
                        fileEvent := new(FileEvent)
                        fileEvent.Name = filePath