mirror of
				https://github.com/docker/compose.git
				synced 2025-11-04 05:34:09 +01:00 
			
		
		
		
	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 (
 | 
					import (
 | 
				
			||||||
	"expvar"
 | 
						"expvar"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/windmilleng/tilt/internal/logger"
 | 
						"github.com/windmilleng/tilt/internal/logger"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -11,7 +13,18 @@ var (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type FileEvent struct {
 | 
					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 {
 | 
					type Notify interface {
 | 
				
			||||||
 | 
				
			|||||||
@ -600,16 +600,16 @@ F:
 | 
				
			|||||||
			f.T().Fatal(err)
 | 
								f.T().Fatal(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case event := <-f.notify.Events():
 | 
							case event := <-f.notify.Events():
 | 
				
			||||||
			if strings.Contains(event.Path, syncPath) {
 | 
								if strings.Contains(event.Path(), syncPath) {
 | 
				
			||||||
				break F
 | 
									break F
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if strings.Contains(event.Path, anySyncPath) {
 | 
								if strings.Contains(event.Path(), anySyncPath) {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Don't bother tracking duplicate changes to the same path
 | 
								// Don't bother tracking duplicate changes to the same path
 | 
				
			||||||
			// for testing.
 | 
								// 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
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,8 @@ import (
 | 
				
			|||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/windmilleng/tilt/internal/logger"
 | 
						"github.com/windmilleng/tilt/internal/logger"
 | 
				
			||||||
	"github.com/windmilleng/tilt/internal/ospath"
 | 
						"github.com/windmilleng/tilt/internal/ospath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -62,9 +64,7 @@ func (d *darwinNotify) loop() {
 | 
				
			|||||||
					continue
 | 
										continue
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				d.events <- FileEvent{
 | 
									d.events <- NewFileEvent(e.Path)
 | 
				
			||||||
					Path: e.Path,
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -133,6 +133,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*darwinNot
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, path := range paths {
 | 
						for _, path := range paths {
 | 
				
			||||||
 | 
							path, err := filepath.Abs(path)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, errors.Wrap(err, "newWatcher")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		dw.initAdd(path)
 | 
							dw.initAdd(path)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -207,6 +207,10 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
 | 
				
			|||||||
	wrappedEvents := make(chan FileEvent)
 | 
						wrappedEvents := make(chan FileEvent)
 | 
				
			||||||
	notifyList := make(map[string]bool, len(paths))
 | 
						notifyList := make(map[string]bool, len(paths))
 | 
				
			||||||
	for _, path := range paths {
 | 
						for _, path := range paths {
 | 
				
			||||||
 | 
							path, err := filepath.Abs(path)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, errors.Wrap(err, "newWatcher")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		notifyList[path] = true
 | 
							notifyList[path] = true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user