Skip to content

Commit be71f8e

Browse files
committed
commands: Move the CHMOD event filter up
To prevent ghost rebuilds (from VSCode and possibly others). Fixes gohugoio#13373
1 parent 5e4ffa0 commit be71f8e

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

commands/hugobuilder.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,20 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
663663
var n int
664664
for _, ev := range evs {
665665
keep := true
666-
if ev.Has(fsnotify.Create) || ev.Has(fsnotify.Write) {
666+
// Write and rename operations are often followed by CHMOD.
667+
// There may be valid use cases for rebuilding the site on CHMOD,
668+
// but that will require more complex logic than this simple conditional.
669+
// On OS X this seems to be related to Spotlight, see:
670+
// https://github.com/go-fsnotify/fsnotify/issues/15
671+
// A workaround is to put your site(s) on the Spotlight exception list,
672+
// but that may be a little mysterious for most end users.
673+
// So, for now, we skip reload on CHMOD.
674+
// We do have to check for WRITE though. On slower laptops a Chmod
675+
// could be aggregated with other important events, and we still want
676+
// to rebuild on those
677+
if ev.Op == fsnotify.Chmod {
678+
keep = false
679+
} else if ev.Has(fsnotify.Create) || ev.Has(fsnotify.Write) {
667680
if _, err := os.Stat(ev.Name); err != nil {
668681
keep = false
669682
}
@@ -805,21 +818,6 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
805818
continue
806819
}
807820

808-
// Write and rename operations are often followed by CHMOD.
809-
// There may be valid use cases for rebuilding the site on CHMOD,
810-
// but that will require more complex logic than this simple conditional.
811-
// On OS X this seems to be related to Spotlight, see:
812-
// https://github.com/go-fsnotify/fsnotify/issues/15
813-
// A workaround is to put your site(s) on the Spotlight exception list,
814-
// but that may be a little mysterious for most end users.
815-
// So, for now, we skip reload on CHMOD.
816-
// We do have to check for WRITE though. On slower laptops a Chmod
817-
// could be aggregated with other important events, and we still want
818-
// to rebuild on those
819-
if ev.Op&(fsnotify.Chmod|fsnotify.Write|fsnotify.Create) == fsnotify.Chmod {
820-
continue
821-
}
822-
823821
walkAdder := func(path string, f hugofs.FileMetaInfo) error {
824822
if f.IsDir() {
825823
c.r.logger.Println("adding created directory to watchlist", path)

0 commit comments

Comments
 (0)