diff --git a/internal/watch/notify_test.go b/internal/watch/notify_test.go index 69ff0787a8..432247b7e6 100644 --- a/internal/watch/notify_test.go +++ b/internal/watch/notify_test.go @@ -28,6 +28,14 @@ func TestNoEvents(t *testing.T) { f.assertEvents() } +func TestNoWatches(t *testing.T) { + f := newNotifyFixture(t) + defer f.tearDown() + f.paths = nil + f.rebuildWatcher() + f.assertEvents() +} + func TestEventOrdering(t *testing.T) { f := newNotifyFixture(t) defer f.tearDown() @@ -586,6 +594,10 @@ func (f *notifyFixture) consumeEventsInBackground(ctx context.Context) chan erro } func (f *notifyFixture) fsync() { + if len(f.paths) == 0 { + return + } + syncPathBase := fmt.Sprintf("sync-%d.txt", time.Now().UnixNano()) syncPath := filepath.Join(f.paths[0], syncPathBase) anySyncPath := filepath.Join(f.paths[0], "sync-") diff --git a/internal/watch/watcher_darwin.go b/internal/watch/watcher_darwin.go index ae757f1a43..69a5be50a5 100644 --- a/internal/watch/watcher_darwin.go +++ b/internal/watch/watcher_darwin.go @@ -89,6 +89,10 @@ func (d *darwinNotify) initAdd(name string) { } func (d *darwinNotify) Start() error { + if len(d.stream.Paths) == 0 { + return nil + } + numberOfWatches.Add(int64(len(d.stream.Paths))) d.stream.Start() diff --git a/internal/watch/watcher_naive.go b/internal/watch/watcher_naive.go index b543a140a7..569b680805 100644 --- a/internal/watch/watcher_naive.go +++ b/internal/watch/watcher_naive.go @@ -35,6 +35,10 @@ type naiveNotify struct { } func (d *naiveNotify) Start() error { + if len(d.notifyList) == 0 { + return nil + } + for name := range d.notifyList { fi, err := os.Stat(name) if err != nil && !os.IsNotExist(err) {