From b9b70fb6b085e5141078bee80f342d2a9fdc2f5e Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Tue, 10 Mar 2015 16:55:23 -0600 Subject: [PATCH] Skip directories like node_modules from the watchlist A local `node_modules` directory can easily contain tens of thousands of files, easily exhausting the tiny default max open files limit especially on OS X Yosemite, in spite of the fact that Hugo already had code in place since February 2014 to try to raise the maxfiles ulimit. Also skip `.git` and `bower_components` directories. The file watching situation will improve when https://github.com/go-fsnotify/fsevents become ready, but until then, we will be thrifty. :-) Thanks to @chibicode for the suggestion. See #168 for continued discussions. --- commands/hugo.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/hugo.go b/commands/hugo.go index d3681f1fc..58a84cb14 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -292,6 +292,7 @@ func copyStatic() error { return syncer.Sync(publishDir, staticDir) } +// getDirList provides NewWatcher() with a list of directories to watch for changes. func getDirList() []string { var a []string walker := func(path string, fi os.FileInfo, err error) error { @@ -318,6 +319,10 @@ func getDirList() []string { } if fi.IsDir() { + if fi.Name() == ".git" || + fi.Name() == "node_modules" || fi.Name() == "bower_components" { + return filepath.SkipDir + } a = append(a, path) } return nil