e.mask&IN_DELETE_SELF == IN_DELETE_SELF ||
e.mask&IN_MOVED_FROM == IN_MOVED_FROM ||
e.mask&IN_MOVE_SELF == IN_MOVE_SELF) {
- if _, statErr := os.Stat(e.Name); os.IsNotExist(statErr) {
+ if _, statErr := os.Lstat(e.Name); os.IsNotExist(statErr) {
return true
}
}
import (
"os"
"testing"
+ "time"
)
func TestFsnotifyFakeSymlink(t *testing.T) {
}
defer os.RemoveAll(testDir)
- if os.Symlink("_test/zzz", "_test/zzznew") != nil {
- t.Fatalf("Failed to create bogus symlink: %s", err)
- }
- t.Logf("Created bogus symlink")
-
var errorsReceived = 0
// Receive errors on the error channel on a separate goroutine
go func() {
}
}()
+ // Count the CREATE events received
+ var createEventsReceived = 0
+ var otherEventsReceived = 0
+ go func() {
+ for ev := range watcher.Event {
+ t.Logf("Received error: %s", ev)
+ if ev.IsCreate() {
+ createEventsReceived++
+ } else {
+ otherEventsReceived++
+ }
+ }
+ }()
+
// Add a watch for testDir
err = watcher.Watch(testDir)
if err != nil {
t.Fatalf("Watcher.Watch() failed: %s", err)
}
+ if os.Symlink("_test/zzz", "_test/zzznew") != nil {
+ t.Fatalf("Failed to create bogus symlink: %s", err)
+ }
+ t.Logf("Created bogus symlink")
+
+ // We expect this event to be received almost immediately, but let's wait 500 ms to be sure
+ time.Sleep(500 * time.Millisecond)
+
// Should not be error, just no events for broken links (watching nothing)
if errorsReceived > 0 {
t.Fatal("fsnotify errors have been received.")
}
+ if otherEventsReceived > 0 {
+ t.Fatal("fsnotify other events received on the broken link")
+ }
+
+ // Except for 1 create event (for the link itself)
+ if createEventsReceived == 0 {
+ t.Fatal("fsnotify create events were not received after 500 ms")
+ }
+ if createEventsReceived > 1 {
+ t.Fatal("fsnotify more create events received than expected")
+ }
// Try closing the fsnotify instance
t.Log("calling Close()")