watcher: Begin watching added directories before walking them to add subdirectories

This commit is contained in:
Aaron Lindsay 2013-09-05 19:58:32 -04:00
parent 90533c9e2d
commit d97b424e98

View File

@ -43,6 +43,11 @@ func StartWatching(watchDir string, fileUpdates chan *asink.Event) {
//if a directory was created, begin recursively watching all its subdirectories //if a directory was created, begin recursively watching all its subdirectories
if fi, err := os.Stat(ev.Name); err == nil && fi.IsDir() { if fi, err := os.Stat(ev.Name); err == nil && fi.IsDir() {
if ev.IsCreate() { 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) 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 //TODO do a scan of this directory so we ensure any file events we missed before starting to watch this directory are caught
} }