From bf36090b4b325d041bcf7fb1df80a4b0af2d07ed Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Sat, 28 Apr 2012 11:06:35 -0500 Subject: [PATCH] BSD - Have symlink behavior match Linux --- fsnotify_bsd.go | 9 +++++++-- fsnotify_test.go | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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 -- 2.50.1