I am trying to create a directory watcher using fsnotify on macos. On my tests, I’ve noticed that when I remove a file, i am receiving a rename event notification, not a remove. Would you guys know if I am missing something?
The following code is based on example_test.go
package main
import (
"log"
"github.com/fsnotify/fsnotify"
)
func main() {
ExampleNewWatcher()
}
func ExampleNewWatcher() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
log.Println("event:", event)
case err := <-watcher.Errors:
log.Println("error:", err)
}
}
}()
err = watcher.Add("/Users/blabla/go/src/sync")
if err != nil {
log.Fatal(err)
}
<-done
}
Thank you for your help!