Skip to content

Commit 37647bc

Browse files
nicksndeloof
authored andcommitted
watch: skip setup if nothing is being watched (docker#1861)
1 parent 21e5d56 commit 37647bc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

pkg/watch/notify_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func TestNoEvents(t *testing.T) {
2828
f.assertEvents()
2929
}
3030

31+
func TestNoWatches(t *testing.T) {
32+
f := newNotifyFixture(t)
33+
defer f.tearDown()
34+
f.paths = nil
35+
f.rebuildWatcher()
36+
f.assertEvents()
37+
}
38+
3139
func TestEventOrdering(t *testing.T) {
3240
f := newNotifyFixture(t)
3341
defer f.tearDown()
@@ -586,6 +594,10 @@ func (f *notifyFixture) consumeEventsInBackground(ctx context.Context) chan erro
586594
}
587595

588596
func (f *notifyFixture) fsync() {
597+
if len(f.paths) == 0 {
598+
return
599+
}
600+
589601
syncPathBase := fmt.Sprintf("sync-%d.txt", time.Now().UnixNano())
590602
syncPath := filepath.Join(f.paths[0], syncPathBase)
591603
anySyncPath := filepath.Join(f.paths[0], "sync-")

pkg/watch/watcher_darwin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (d *darwinNotify) initAdd(name string) {
8989
}
9090

9191
func (d *darwinNotify) Start() error {
92+
if len(d.stream.Paths) == 0 {
93+
return nil
94+
}
95+
9296
numberOfWatches.Add(int64(len(d.stream.Paths)))
9397

9498
d.stream.Start()

pkg/watch/watcher_naive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ type naiveNotify struct {
3535
}
3636

3737
func (d *naiveNotify) Start() error {
38+
if len(d.notifyList) == 0 {
39+
return nil
40+
}
41+
3842
for name := range d.notifyList {
3943
fi, err := os.Stat(name)
4044
if err != nil && !os.IsNotExist(err) {

0 commit comments

Comments
 (0)