]> go.fuhry.dev Git - fsnotify.git/commitdiff
BSD - Have symlink behavior match Linux
authorChris Howey <chris@howey.me>
Sat, 28 Apr 2012 16:06:35 +0000 (11:06 -0500)
committerChris Howey <chris@howey.me>
Sat, 28 Apr 2012 16:06:35 +0000 (11:06 -0500)
fsnotify_bsd.go
fsnotify_test.go

index e06dfc11e6fd64943f8d535cba940414881ca9a1..2f5d7b4b1fc715f9c35a1f034ce2bea836ac01ca 100644 (file)
@@ -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
                        }
                }
 
index 55220baedb59172c2e0b0ba69952d83809f40a7b..107dd316ef0015a462bb5c130fec4b67f94b39bc 100644 (file)
@@ -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