From d6c1d1343b6137974c0440d97c27c12e66532e02 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 11 Apr 2016 23:21:21 +0100 Subject: [PATCH] Continuserv: Reduce number of watches rather than trying to watch half the filesystem, be a bit more conservative in what we put watches on. This means that we don't end up dying with "No space on device" (thanks for that, Linux.) --- scripts/continuserv/main.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/continuserv/main.go b/scripts/continuserv/main.go index a1295077f..4d97d7901 100644 --- a/scripts/continuserv/main.go +++ b/scripts/continuserv/main.go @@ -50,7 +50,13 @@ func main() { } } - filepath.Walk(dir, makeWalker(w)) + walker := makeWalker(dir, w) + paths := []string{"api", "changelogs", "event-schemas", "scripts", + "specification", "templating"} + + for _, p := range paths { + filepath.Walk(path.Join(dir, p), walker) + } wg.Add(1) populateOnce(dir) @@ -77,11 +83,25 @@ func watchFS(ch chan struct{}, w *fsnotify.Watcher) { } } -func makeWalker(w *fsnotify.Watcher) filepath.WalkFunc { +func makeWalker(base string, w *fsnotify.Watcher) filepath.WalkFunc { return func(path string, _ os.FileInfo, err error) error { if err != nil { log.Fatalf("Error walking: %v", err) } + + rel, err := filepath.Rel(base, path) + if err != nil { + log.Fatalf("Failed to get relative path of %s: %v", path, err) + } + + // skip a few things that we know don't form part of the spec + if rel == "api/node_modules" || + rel == "scripts/gen" || + rel == "scripts/tmp" { + return filepath.SkipDir + } + + // log.Printf("Adding watch on %s", path) if err := w.Add(path); err != nil { log.Fatalf("Failed to add watch: %v", err) } @@ -95,20 +115,12 @@ func filter(e fsnotify.Event) bool { if e.Op != fsnotify.Write { return false } + // Avoid some temp files that vim writes if strings.HasSuffix(e.Name, "~") || strings.HasSuffix(e.Name, ".swp") || strings.HasPrefix(e.Name, ".") { return false } - // Ignore the .git directory - It's very noisy - if strings.Contains(e.Name, "/.git/") { - return false - } - - // Avoid infinite cycles being caused by writing actual output - if strings.Contains(e.Name, "/tmp/") || strings.Contains(e.Name, "/gen/") { - return false - } return true }