mirror of https://github.com/docker/compose.git
watch: FileEvents must always be absolute (#1841)
there were a lot of confused tests that were using relative paths, then trying to workaround this
This commit is contained in:
parent
390d5cf165
commit
21e5d564af
|
@ -2,6 +2,8 @@ package watch
|
|||
|
||||
import (
|
||||
"expvar"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/windmilleng/tilt/internal/logger"
|
||||
)
|
||||
|
@ -11,7 +13,18 @@ var (
|
|||
)
|
||||
|
||||
type FileEvent struct {
|
||||
Path string
|
||||
path string
|
||||
}
|
||||
|
||||
func NewFileEvent(p string) FileEvent {
|
||||
if !filepath.IsAbs(p) {
|
||||
panic(fmt.Sprintf("NewFileEvent only accepts absolute paths. Actual: %s", p))
|
||||
}
|
||||
return FileEvent{path: p}
|
||||
}
|
||||
|
||||
func (e FileEvent) Path() string {
|
||||
return e.path
|
||||
}
|
||||
|
||||
type Notify interface {
|
||||
|
|
|
@ -600,16 +600,16 @@ F:
|
|||
f.T().Fatal(err)
|
||||
|
||||
case event := <-f.notify.Events():
|
||||
if strings.Contains(event.Path, syncPath) {
|
||||
if strings.Contains(event.Path(), syncPath) {
|
||||
break F
|
||||
}
|
||||
if strings.Contains(event.Path, anySyncPath) {
|
||||
if strings.Contains(event.Path(), anySyncPath) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Don't bother tracking duplicate changes to the same path
|
||||
// for testing.
|
||||
if len(f.events) > 0 && f.events[len(f.events)-1].Path == event.Path {
|
||||
if len(f.events) > 0 && f.events[len(f.events)-1].Path() == event.Path() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/windmilleng/tilt/internal/logger"
|
||||
"github.com/windmilleng/tilt/internal/ospath"
|
||||
|
||||
|
@ -62,9 +64,7 @@ func (d *darwinNotify) loop() {
|
|||
continue
|
||||
}
|
||||
|
||||
d.events <- FileEvent{
|
||||
Path: e.Path,
|
||||
}
|
||||
d.events <- NewFileEvent(e.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +133,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*darwinNot
|
|||
}
|
||||
|
||||
for _, path := range paths {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "newWatcher")
|
||||
}
|
||||
dw.initAdd(path)
|
||||
}
|
||||
|
||||
|
|
|
@ -207,6 +207,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
|
|||
wrappedEvents := make(chan FileEvent)
|
||||
notifyList := make(map[string]bool, len(paths))
|
||||
for _, path := range paths {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "newWatcher")
|
||||
}
|
||||
notifyList[path] = true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue