Skip to content

Commit

Permalink
check ignorePrefixes on absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoyamachi committed May 13, 2019
1 parent 597cf0e commit 2b84d3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions multiwatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ commands = ["sleep 1", "sleep 1", "ls /sfsdfsdf"]

[[watch]]
name = "tests"
paths = ["vendor/github.com"]
ignorePrefixes = ["fsnotify"]
paths = ["."]
ignorePrefixes = ["vendor"]
commands = ["sleep 5"]
17 changes: 14 additions & 3 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,25 @@ func (w *Watcher) registerFiles() error {
func (w *Watcher) watchDir(baseDir string) func(path string, fi os.FileInfo, err error) error {
return func(path string, fi os.FileInfo, err error) error {
if fi.Mode().IsDir() {
// check absolute path
absPath, err := filepath.Abs(path)
if err != nil {
return err
}

// check ignore prefixes
absBaseDir, err := filepath.Abs(baseDir)
if err != nil {
return err
}

for _, ignorePrefix := range w.config.IgnorePrefixes {
targetPath := fmt.Sprintf("%s/%s", baseDir, ignorePrefix)
if strings.HasPrefix(path, targetPath) {
targetPath := fmt.Sprintf("%s/%s", absBaseDir, ignorePrefix)
if strings.HasPrefix(absPath, targetPath) {
return nil
}
}
return w.watcher.Add(path)
return w.watcher.Add(absPath)
}
return nil
}
Expand Down

0 comments on commit 2b84d3d

Please sign in to comment.