2018-08-16 20:53:47 +02:00
|
|
|
package watch
|
|
|
|
|
2019-07-11 23:54:50 +02:00
|
|
|
import (
|
|
|
|
"expvar"
|
|
|
|
|
|
|
|
"github.com/windmilleng/tilt/internal/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
numberOfWatches = expvar.NewInt("watch.naive.numberOfWatches")
|
|
|
|
)
|
2019-07-11 17:40:40 +02:00
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
type FileEvent struct {
|
|
|
|
Path string
|
|
|
|
}
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
type Notify interface {
|
2019-07-11 17:40:40 +02:00
|
|
|
// Start watching the paths set at init time
|
|
|
|
Start() error
|
|
|
|
|
|
|
|
// Stop watching and close all channels
|
2018-08-16 20:53:47 +02:00
|
|
|
Close() error
|
2019-07-11 17:40:40 +02:00
|
|
|
|
|
|
|
// A channel to read off incoming file changes
|
2018-08-22 21:33:06 +02:00
|
|
|
Events() chan FileEvent
|
2019-07-11 17:40:40 +02:00
|
|
|
|
|
|
|
// A channel to read off show-stopping errors
|
2018-08-16 20:53:47 +02:00
|
|
|
Errors() chan error
|
|
|
|
}
|
2019-07-11 17:40:40 +02:00
|
|
|
|
|
|
|
// When we specify directories to watch, we often want to
|
|
|
|
// ignore some subset of the files under those directories.
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
// - Watch /src/repo, but ignore /src/repo/.git
|
|
|
|
// - Watch /src/repo, but ignore everything in /src/repo/bazel-bin except /src/repo/bazel-bin/app-binary
|
|
|
|
//
|
|
|
|
// The PathMatcher inteface helps us manage these ignores.
|
|
|
|
// By design, fileutils.PatternMatcher (the interface that implements dockerignore)
|
|
|
|
// satisfies this interface
|
|
|
|
// https://godoc.org/github.com/docker/docker/pkg/fileutils#PatternMatcher
|
|
|
|
type PathMatcher interface {
|
|
|
|
Matches(file string) (bool, error)
|
|
|
|
Exclusions() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type EmptyMatcher struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }
|
|
|
|
func (EmptyMatcher) Exclusions() bool { return false }
|
|
|
|
|
|
|
|
var _ PathMatcher = EmptyMatcher{}
|
|
|
|
|
|
|
|
func NewWatcher(paths []string, ignore PathMatcher, l logger.Logger) (Notify, error) {
|
|
|
|
return newWatcher(paths, ignore, l)
|
|
|
|
}
|