From: Chris Howey Date: Sat, 28 Apr 2012 16:06:35 +0000 (-0500) Subject: BSD - Have symlink behavior match Linux X-Git-Tag: v1.7.2~432 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=bf36090b4b325d041bcf7fb1df80a4b0af2d07ed;p=fsnotify.git BSD - Have symlink behavior match Linux --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index e06dfc1..2f5d7b4 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -104,15 +104,20 @@ func (w *Watcher) addWatch(path string, flags uint32) error { } // Follow Symlinks + // Unfortunately, Linux can add bogus symlinks to watch list without + // issue, and Windows can't do symlinks period (AFAIK). To maintain + // consistency, we will act like everything is fine. There will simply + // be no file events for broken symlinks. + // Hence the returns of nil on errors. for fi.Mode()&os.ModeSymlink == os.ModeSymlink { path, errstat = os.Readlink(path) if errstat != nil { - return errstat + return nil } fi, errstat = os.Lstat(path) if errstat != nil { - return errstat + return nil } } diff --git a/fsnotify_test.go b/fsnotify_test.go index 55220ba..107dd31 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -252,9 +252,9 @@ func TestFsnotifyFakeSymlink(t *testing.T) { t.Fatalf("Watcher.Watch() failed: %s", err) } - // We expect this event to be received immediately, as they happen during Watch() call - if errorsReceived == 0 { - t.Fatal("fsnotify errors have not been received.") + // Should not be error, just no events for broken links (watching nothing) + if errorsReceived > 0 { + t.Fatal("fsnotify errors have been received.") } // Try closing the fsnotify instance