Skip to content

Commit 21e5d56

Browse files
nicksndeloof
authored andcommitted
watch: FileEvents must always be absolute (docker#1841)
there were a lot of confused tests that were using relative paths, then trying to workaround this
1 parent 390d5cf commit 21e5d56

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

pkg/watch/notify.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package watch
22

33
import (
44
"expvar"
5+
"fmt"
6+
"path/filepath"
57

68
"github.com/windmilleng/tilt/internal/logger"
79
)
@@ -11,7 +13,18 @@ var (
1113
)
1214

1315
type FileEvent struct {
14-
Path string
16+
path string
17+
}
18+
19+
func NewFileEvent(p string) FileEvent {
20+
if !filepath.IsAbs(p) {
21+
panic(fmt.Sprintf("NewFileEvent only accepts absolute paths. Actual: %s", p))
22+
}
23+
return FileEvent{path: p}
24+
}
25+
26+
func (e FileEvent) Path() string {
27+
return e.path
1528
}
1629

1730
type Notify interface {

pkg/watch/notify_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,16 @@ F:
600600
f.T().Fatal(err)
601601

602602
case event := <-f.notify.Events():
603-
if strings.Contains(event.Path, syncPath) {
603+
if strings.Contains(event.Path(), syncPath) {
604604
break F
605605
}
606-
if strings.Contains(event.Path, anySyncPath) {
606+
if strings.Contains(event.Path(), anySyncPath) {
607607
continue
608608
}
609609

610610
// Don't bother tracking duplicate changes to the same path
611611
// for testing.
612-
if len(f.events) > 0 && f.events[len(f.events)-1].Path == event.Path {
612+
if len(f.events) > 0 && f.events[len(f.events)-1].Path() == event.Path() {
613613
continue
614614
}
615615

pkg/watch/watcher_darwin.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"path/filepath"
55
"time"
66

7+
"github.com/pkg/errors"
8+
79
"github.com/windmilleng/tilt/internal/logger"
810
"github.com/windmilleng/tilt/internal/ospath"
911

@@ -62,9 +64,7 @@ func (d *darwinNotify) loop() {
6264
continue
6365
}
6466

65-
d.events <- FileEvent{
66-
Path: e.Path,
67-
}
67+
d.events <- NewFileEvent(e.Path)
6868
}
6969
}
7070
}
@@ -133,6 +133,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*darwinNot
133133
}
134134

135135
for _, path := range paths {
136+
path, err := filepath.Abs(path)
137+
if err != nil {
138+
return nil, errors.Wrap(err, "newWatcher")
139+
}
136140
dw.initAdd(path)
137141
}
138142

pkg/watch/watcher_naive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
207207
wrappedEvents := make(chan FileEvent)
208208
notifyList := make(map[string]bool, len(paths))
209209
for _, path := range paths {
210+
path, err := filepath.Abs(path)
211+
if err != nil {
212+
return nil, errors.Wrap(err, "newWatcher")
213+
}
210214
notifyList[path] = true
211215
}
212216

0 commit comments

Comments
 (0)