]> go.fuhry.dev Git - fsnotify.git/commitdiff
kqueue: cleanup internal watch before sending remove event
authorNathan Youngman <git@nathany.com>
Sat, 13 Dec 2014 06:15:00 +0000 (23:15 -0700)
committerNathan Youngman <git@nathany.com>
Sat, 13 Dec 2014 06:15:00 +0000 (23:15 -0700)
#51 if the calling code were to Add the same file again it sometimes would result in a bad file descriptor (thought it was alreadyWatching)

CHANGELOG.md
kqueue.go

index 93c93394dbd60dd2dd214bc8a87aee870b568d29..251ad6e970a2021ad8e9bd4ba92bacf4450c7db0 100644 (file)
@@ -10,6 +10,7 @@
     * remove calls to os.NewSyscallError
 * More efficient string concatenation for Event.String() [#52](https://github.com/go-fsnotify/fsnotify/pull/52) (thanks @mdlayher)
 * kqueue: fix regression in  rework causing subdirectories to be watched [#48](https://github.com/go-fsnotify/fsnotify/issues/48)
+* kqueue: cleanup internal watch before sending remove event [#51](https://github.com/go-fsnotify/fsnotify/issues/48)
 
 ## v1.0.4 / 2014-09-07
 
index 545c6c9d298fa5f1c4f3688fb34f1c85f35de9c8..1636e74f39f60ab0217148e37ba5058406b447aa 100644 (file)
--- a/kqueue.go
+++ b/kqueue.go
@@ -283,6 +283,13 @@ func (w *Watcher) readEvents() {
                                }
                        }
 
+                       if event.Op&Rename == Rename || event.Op&Remove == Remove {
+                               w.Remove(event.Name)
+                               w.mu.Lock()
+                               delete(w.fileExists, event.Name)
+                               w.mu.Unlock()
+                       }
+
                        if path.isDir && event.Op&Write == Write && !(event.Op&Remove == Remove) {
                                w.sendDirectoryChangeEvents(event.Name)
                        } else {
@@ -290,12 +297,6 @@ func (w *Watcher) readEvents() {
                                w.Events <- event
                        }
 
-                       if event.Op&Rename == Rename || event.Op&Remove == Remove {
-                               w.Remove(event.Name)
-                               w.mu.Lock()
-                               delete(w.fileExists, event.Name)
-                               w.mu.Unlock()
-                       }
                        if event.Op&Remove == Remove {
                                // Look for a file that may have overwritten this.
                                // For example, mv f1 f2 will delete f2, then create f2.