From f29a206ffd6c2365d6a727a4bf5ac180346b7a7e Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Sun, 18 May 2014 09:26:12 -0400 Subject: [PATCH 1/3] Check if event is just an attrib flag that can be skipped --- main.go | 3 ++- runner/watcher.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1dea9dd..dbce1f9 100644 --- a/main.go +++ b/main.go @@ -15,8 +15,9 @@ package main import ( "flag" "fmt" - "github.com/pilu/fresh/runner" "os" + + "github.com/pkieltyka/fresh/runner" ) func main() { diff --git a/runner/watcher.go b/runner/watcher.go index 7df2706..53ff2dc 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -1,10 +1,11 @@ package runner import ( - "github.com/howeyc/fsnotify" "os" "path/filepath" "strings" + + "github.com/howeyc/fsnotify" ) func watchFolder(path string) { @@ -17,7 +18,7 @@ func watchFolder(path string) { for { select { case ev := <-watcher.Event: - if isWatchedFile(ev.Name) { + if isWatchedFile(ev.Name) && !ev.IsAttrib() { watcherLog("sending event %s", ev) startChannel <- ev.String() } From dfdf37b172abff85d1a6d89d8b85ec61154e1ff9 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Sat, 16 Aug 2014 14:01:57 -0400 Subject: [PATCH 2/3] Add 'watch_path' setting to make fresh more flexible with different app structures --- main.go | 5 +++++ runner.conf.sample | 1 + runner/settings.go | 8 +++++++- runner/watcher.go | 8 ++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index dbce1f9..2145391 100644 --- a/main.go +++ b/main.go @@ -22,8 +22,12 @@ import ( func main() { configPath := flag.String("c", "", "config file path") + watchPath := flag.String("w", "", "path to watch files") + flag.Parse() + // TODO: nice big refactoring of the flags + config + if *configPath != "" { if _, err := os.Stat(*configPath); err != nil { fmt.Printf("Can't find config file `%s`\n", *configPath) @@ -32,6 +36,7 @@ func main() { os.Setenv("RUNNER_CONFIG_PATH", *configPath) } } + os.Setenv("RUNNER_WATCH_PATH", *watchPath) runner.Start() } diff --git a/runner.conf.sample b/runner.conf.sample index 5ac3c05..23a4beb 100644 --- a/runner.conf.sample +++ b/runner.conf.sample @@ -1,4 +1,5 @@ root: . +watch_path: . tmp_path: ./tmp build_name: runner-build build_log: runner-build-errors.log diff --git a/runner/settings.go b/runner/settings.go index 61e2412..ad513ec 100644 --- a/runner/settings.go +++ b/runner/settings.go @@ -2,12 +2,13 @@ package runner import ( "fmt" - "github.com/pilu/config" "os" "path/filepath" "strconv" "strings" "time" + + "github.com/pilu/config" ) const ( @@ -18,6 +19,7 @@ const ( var settings = map[string]string{ "config_path": "./runner.conf", "root": ".", + "watch_path": ".", "tmp_path": "./tmp", "build_name": "runner-build", "build_log": "runner-build-errors.log", @@ -108,6 +110,10 @@ func root() string { return settings["root"] } +func watchPath() string { + return settings["watch_path"] +} + func tmpPath() string { return settings["tmp_path"] } diff --git a/runner/watcher.go b/runner/watcher.go index 53ff2dc..18853c1 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -37,8 +37,12 @@ func watchFolder(path string) { } func watch() { - root := root() - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + watchPath, err := filepath.Abs(watchPath()) + if err != nil { + fatal(err) + } + + filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error { if info.IsDir() && !isTmpDir(path) { if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") { return filepath.SkipDir From 0c7532a1e40af32ad4005e15cf4dbdfa952a5fc4 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Tue, 25 Aug 2015 15:20:46 -0400 Subject: [PATCH 3/3] Ignore vendor dir for file changes --- runner/utils.go | 5 +++++ runner/watcher.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/runner/utils.go b/runner/utils.go index 93096ff..282cce7 100644 --- a/runner/utils.go +++ b/runner/utils.go @@ -23,6 +23,11 @@ func isTmpDir(path string) bool { return absolutePath == absoluteTmpPath } +func isVendorDir(path string) bool { + absolutePath, _ := filepath.Abs(path) + return filepath.Base(absolutePath) == "vendor" +} + func isWatchedFile(path string) bool { absolutePath, _ := filepath.Abs(path) absoluteTmpPath, _ := filepath.Abs(tmpPath()) diff --git a/runner/watcher.go b/runner/watcher.go index 18853c1..5033d14 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -44,7 +44,7 @@ func watch() { filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error { if info.IsDir() && !isTmpDir(path) { - if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") { + if (len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".")) || (isVendorDir(path)) { return filepath.SkipDir }