1
0
Эх сурвалжийг харах

watch: move more of the directory-skipping logic into the interface (#1864)

Nick Santos 6 жил өмнө
parent
commit
a31350ede1

+ 5 - 6
pkg/watch/notify.go

@@ -49,19 +49,18 @@ type Notify interface {
 // - 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
+
+	// If this matches the entire dir, we can often optimize filetree walks a bit.
+	MatchesEntireDir(file string) (bool, error)
 }
 
 type EmptyMatcher struct {
 }
 
-func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }
-func (EmptyMatcher) Exclusions() bool               { return false }
+func (EmptyMatcher) Matches(f string) (bool, error)          { return false, nil }
+func (EmptyMatcher) MatchesEntireDir(f string) (bool, error) { return false, nil }
 
 var _ PathMatcher = EmptyMatcher{}
 

+ 6 - 18
pkg/watch/watcher_naive.go

@@ -207,28 +207,16 @@ func (d *naiveNotify) shouldNotify(path string) bool {
 }
 
 func (d *naiveNotify) shouldSkipDir(path string) (bool, error) {
-	var err error
-	ignore := false
-
 	// If path is directly in the notifyList, we should always watch it.
-	if !d.notifyList[path] {
-		ignore, err = d.ignore.Matches(path)
-		if err != nil {
-			return false, errors.Wrapf(err, "Error matching %s: %v", path, err)
-		}
+	if d.notifyList[path] {
+		return false, nil
 	}
 
-	// The ignore filter is telling us to ignore this file,
-	// but we may have to watch it anyway to catch files underneath it.
-	if ignore {
-		if !d.ignore.Exclusions() {
-			return true, nil
-		}
-
-		// TODO(nick): Add more complex logic for interpreting exclusion patterns.
+	skip, err := d.ignore.MatchesEntireDir(path)
+	if err != nil {
+		return false, errors.Wrap(err, "shouldSkipDir")
 	}
-
-	return false, nil
+	return skip, nil
 }
 
 func (d *naiveNotify) add(path string) error {