From b1c4fa9abe724fadeb662ae5ed634f03b249387d Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Thu, 23 Nov 2017 15:39:20 -0800 Subject: [PATCH] Fix ignored_paths --- watcher.go | 3 ++- watcher_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/watcher.go b/watcher.go index 0e6d5e2..c44ea5f 100644 --- a/watcher.go +++ b/watcher.go @@ -397,7 +397,8 @@ func (p *Project) tool(stop <-chan bool, path string) error { func (p *Project) walk(path string, info os.FileInfo, err error) error { for _, v := range p.Watcher.Ignore { s := append([]string{p.Path}, strings.Split(v, string(os.PathSeparator))...) - if strings.Contains(path, filepath.Join(s...)) { + absolutePath, _ := filepath.Abs(filepath.Join(s...)) + if path == absolutePath || strings.HasPrefix(path, absolutePath+string(os.PathSeparator)) { return nil } } diff --git a/watcher_test.go b/watcher_test.go index 223711f..7c47513 100644 --- a/watcher_test.go +++ b/watcher_test.go @@ -42,6 +42,7 @@ func TestWalk(t *testing.T) { {"/go/project", true}, {"/go/project/main.go", false}, {"/go/project/main_test.go", false}, + {"/go/project/vendorish/foo", true}, // invalid relative path {"./relative/path", true}, {"./relative/path/file.go", false}, @@ -66,7 +67,7 @@ func TestWalk(t *testing.T) { t.Errorf("Exepeted %d files, but was %d", 2, p.files) } - if p.folders != 1 { + if p.folders != 2 { t.Errorf("Exepeted %d folders, but was %d", 2, p.folders) } }