From d97b424e98536609f726b41f705d4f5740284126 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Thu, 5 Sep 2013 19:58:32 -0400 Subject: [PATCH] watcher: Begin watching added directories before walking them to add subdirectories --- asink/watcher.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/asink/watcher.go b/asink/watcher.go index ddaf843..ab6cbdd 100644 --- a/asink/watcher.go +++ b/asink/watcher.go @@ -43,6 +43,11 @@ func StartWatching(watchDir string, fileUpdates chan *asink.Event) { //if a directory was created, begin recursively watching all its subdirectories if fi, err := os.Stat(ev.Name); err == nil && fi.IsDir() { if ev.IsCreate() { + //Note: even though filepath.Walk will visit root, we must watch root first so we catch files/directories created after the walk begins but before this directory begins being watched + err = watcher.Watch(ev.Name) + if err != nil { + panic("Failed to watch " + ev.Name) + } filepath.Walk(ev.Name, watchDirFn) //TODO do a scan of this directory so we ensure any file events we missed before starting to watch this directory are caught }