]> go.fuhry.dev Git - fsnotify.git/commitdiff
Test adding a path more than once; update documentation (#549)
authorMartin Tournoij <martin@arp242.net>
Tue, 17 Jan 2023 17:20:23 +0000 (18:20 +0100)
committerGitHub <noreply@github.com>
Tue, 17 Jan 2023 17:20:23 +0000 (18:20 +0100)
Seems like this doesn't return an error with any backend. Maybe it
should, but we can't really change it because it's not compatible. I
tested with v1.5.4 and v1.4.8 too to make sure it's not a recent
regression, and it behaves identical there too.

Fixes #548

backend_fen.go
backend_inotify.go
backend_kqueue.go
backend_other.go
backend_windows.go
fsnotify_test.go
mkdoc.zsh

index 2c3e43dc3173031cc217bcff5a608bc33f4fab1a..500bd63f325f4c7af6b043ab4a789236cea5ab01 100644 (file)
@@ -197,8 +197,8 @@ func (w *Watcher) Close() error {
 
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or
index 5c5154fe77cead942d5768550491db44c80a8081..fe5033b155b1b9b28906a896d4380a99c588e8ef 100644 (file)
@@ -307,8 +307,8 @@ func (w *Watcher) Close() error {
 
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or
index c02ad5a9e99e69a4dc14d72f17e2d5172aa3b996..9d464504ab7465b73323663b2ed1b9a01549ef65 100644 (file)
@@ -250,8 +250,8 @@ func (w *Watcher) Close() error {
 
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or
index bc1cab11416d45987581bfeeba9a31de331bffc5..1668de9059ad85f9a769e131b7b9fddd9ce3ca4c 100644 (file)
@@ -132,8 +132,8 @@ func (w *Watcher) WatchList() []string { return nil }
 
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or
index 77050aed370bf510334e933d890dad6f88b03f0c..c0359ac8aea26ff1b7f631cd054a6916b1cdf983 100644 (file)
@@ -210,8 +210,8 @@ func (w *Watcher) Close() error {
 
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or
index c88d39f9ceab50f8dbe47114aaf76da4bda4e997..b86d54d5a4306dd4c5eb6bdfbfdbd283e2076918 100644 (file)
@@ -1203,6 +1203,26 @@ func TestAdd(t *testing.T) {
                        t.Errorf("not syscall.EACCESS: %T %#[1]v", err)
                }
        })
+
+       t.Run("add same path twice", func(t *testing.T) {
+               tmp := t.TempDir()
+               w := newCollector(t)
+               if err := w.w.Add(tmp); err != nil {
+                       t.Fatal(err)
+               }
+               if err := w.w.Add(tmp); err != nil {
+                       t.Fatal(err)
+               }
+
+               w.collect(t)
+               touch(t, tmp, "file")
+               rm(t, tmp, "file")
+
+               cmpEvents(t, tmp, w.events(t), newEvents(t, `
+                       create /file
+                       remove /file
+               `))
+       })
 }
 
 // TODO: should also check internal state is correct/cleaned up; e.g. no
index c7180fb2162017b0f8773cd7b8aefa4c37f95826..868d3b80a6f572d57391ca313824b3f616754184 100755 (executable)
--- a/mkdoc.zsh
+++ b/mkdoc.zsh
@@ -77,8 +77,8 @@ EOF
 add=$(<<EOF
 // Add starts monitoring the path for changes.
 //
-// A path can only be watched once; attempting to watch it more than once will
-// return an error. Paths that do not yet exist on the filesystem cannot be
+// A path can only be watched once; watching it more than once is a no-op and will
+// not return an error. Paths that do not yet exist on the filesystem cannot
 // watched.
 //
 // A watch will be automatically removed if the watched path is deleted or