Skip to content

Commit a31350e

Browse files
nicksndeloof
authored andcommitted
watch: move more of the directory-skipping logic into the interface (docker#1864)
1 parent d744c97 commit a31350e

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

pkg/watch/notify.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,18 @@ type Notify interface {
4949
// - Watch /src/repo, but ignore everything in /src/repo/bazel-bin except /src/repo/bazel-bin/app-binary
5050
//
5151
// The PathMatcher inteface helps us manage these ignores.
52-
// By design, fileutils.PatternMatcher (the interface that implements dockerignore)
53-
// satisfies this interface
54-
// https://godoc.org/github.com/docker/docker/pkg/fileutils#PatternMatcher
5552
type PathMatcher interface {
5653
Matches(file string) (bool, error)
57-
Exclusions() bool
54+
55+
// If this matches the entire dir, we can often optimize filetree walks a bit.
56+
MatchesEntireDir(file string) (bool, error)
5857
}
5958

6059
type EmptyMatcher struct {
6160
}
6261

63-
func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }
64-
func (EmptyMatcher) Exclusions() bool { return false }
62+
func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }
63+
func (EmptyMatcher) MatchesEntireDir(f string) (bool, error) { return false, nil }
6564

6665
var _ PathMatcher = EmptyMatcher{}
6766

pkg/watch/watcher_naive.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,16 @@ func (d *naiveNotify) shouldNotify(path string) bool {
207207
}
208208

209209
func (d *naiveNotify) shouldSkipDir(path string) (bool, error) {
210-
var err error
211-
ignore := false
212-
213210
// If path is directly in the notifyList, we should always watch it.
214-
if !d.notifyList[path] {
215-
ignore, err = d.ignore.Matches(path)
216-
if err != nil {
217-
return false, errors.Wrapf(err, "Error matching %s: %v", path, err)
218-
}
211+
if d.notifyList[path] {
212+
return false, nil
219213
}
220214

221-
// The ignore filter is telling us to ignore this file,
222-
// but we may have to watch it anyway to catch files underneath it.
223-
if ignore {
224-
if !d.ignore.Exclusions() {
225-
return true, nil
226-
}
227-
228-
// TODO(nick): Add more complex logic for interpreting exclusion patterns.
215+
skip, err := d.ignore.MatchesEntireDir(path)
216+
if err != nil {
217+
return false, errors.Wrap(err, "shouldSkipDir")
229218
}
230-
231-
return false, nil
219+
return skip, nil
232220
}
233221

234222
func (d *naiveNotify) add(path string) error {

0 commit comments

Comments
 (0)