kqueue: cleanup internal watch before sending remove event
#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)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93c9339..251ad6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/kqueue.go b/kqueue.go
index 545c6c9..1636e74 100644
--- a/kqueue.go
+++ b/kqueue.go
@@ -283,6 +283,13 @@
}
}
+ 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 @@
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.