Skip to content

Commit

Permalink
watch: skip setup if nothing is being watched (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks authored Jul 15, 2019
1 parent 0918877 commit b712d3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/watch/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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-")
Expand Down
4 changes: 4 additions & 0 deletions internal/watch/watcher_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions internal/watch/watcher_naive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b712d3b

Please sign in to comment.