From de2fec6b35187a470a91f4bc5abd6f56c764f6b0 Mon Sep 17 00:00:00 2001 From: RS Date: Wed, 20 Sep 2017 17:46:32 -0700 Subject: [PATCH] Re-add watch (#60) --- .travis.yml | 2 +- client/watcher/watcher.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7e501f3..959c467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: required language: go -go: 1.6 +go: 1.8 services: - docker diff --git a/client/watcher/watcher.go b/client/watcher/watcher.go index 74b5dd5..02afb81 100644 --- a/client/watcher/watcher.go +++ b/client/watcher/watcher.go @@ -38,6 +38,8 @@ func New(path string) (w *Watcher) { return nil } + printer.Logf("watching path`: %s", path) + w = &Watcher{ path: path, } @@ -66,7 +68,6 @@ func (w *Watcher) Init() error { return nil } -// Watch observes WRITE events, forwarding them to `Updated` func (w *Watcher) Watch() { done := make(chan bool) go func() { @@ -79,11 +80,17 @@ func (w *Watcher) Watch() { event.Op&fsnotify.Chmod == fsnotify.Chmod { err := w.UpdateBytes() if err != nil { - printer.LogErrf("[dcdr] UpdateBytes error: %v", err) + printer.LogErrf("UpdateBytes error: %v", err) + } + + // Rewatch the path + err = w.watcher.Add(w.path) + if err != nil { + printer.LogErrf("fsnotify Add error: %v", err) } } case err := <-w.watcher.Errors: - printer.LogErrf("[dcdr] watch error: %v", err) + printer.LogErrf("watch error: %v", err) } w.mu.Unlock() }