Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-02 10:54:03 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-04 17:12:28 +0300
commit24ce98b6d10b2088af61c15112f5c5ed915a0c35 (patch)
tree88b4090f4997b1763a1d9a49bcfa4ba92500647e /commands
parent0019d60f67b6c4dde085753641a917fcd0aa4c76 (diff)
Add polling as a fallback to native filesystem events in server watch
Fixes #8720 Fixes #6849 Fixes #7930
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go2
-rw-r--r--commands/hugo.go11
-rw-r--r--commands/server.go2
3 files changed, 10 insertions, 5 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 1135dc01a..6aacc8e0b 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -204,6 +204,7 @@ type hugoBuilderCommon struct {
environment string
buildWatch bool
+ poll bool
gc bool
@@ -291,6 +292,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&cc.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. http://spf13.com/")
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date and author info to the pages")
cmd.Flags().BoolVar(&cc.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
+ cmd.Flags().BoolVar(&cc.poll, "poll", false, "use a poll based approach to watch for file system changes")
cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions")
cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics")
diff --git a/commands/hugo.go b/commands/hugo.go
index fddbe2b77..7f3b41048 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -523,7 +523,7 @@ func (c *commandeer) build() error {
c.logger.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
c.logger.Println("Press Ctrl+C to stop")
- watcher, err := c.newWatcher(watchDirs...)
+ watcher, err := c.newWatcher(c.h.poll, watchDirs...)
checkErr(c.Logger, err)
defer watcher.Close()
@@ -820,7 +820,7 @@ func (c *commandeer) fullRebuild(changeType string) {
}
// newWatcher creates a new watcher to watch filesystem events.
-func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
+func (c *commandeer) newWatcher(poll bool, dirList ...string) (*watcher.Batcher, error) {
if runtime.GOOS == "darwin" {
tweakLimit()
}
@@ -830,7 +830,10 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
return nil, err
}
- watcher, err := watcher.New(1 * time.Second)
+ // The second interval is used by the poll based watcher.
+ // Setting a shorter interval would make it snappier,
+ // but it would consume more CPU.
+ watcher, err := watcher.New(500*time.Millisecond, 700*time.Millisecond, poll)
if err != nil {
return nil, err
}
@@ -859,7 +862,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
// Need to reload browser to show the error
livereload.ForceRefresh()
}
- case err := <-watcher.Errors:
+ case err := <-watcher.Errors():
if err != nil {
c.logger.Errorln("Error while watching:", err)
}
diff --git a/commands/server.go b/commands/server.go
index 02db354ba..5c8c778d4 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -262,7 +262,7 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
for _, group := range watchGroups {
jww.FEEDBACK.Printf("Watching for changes in %s\n", group)
}
- watcher, err := c.newWatcher(watchDirs...)
+ watcher, err := c.newWatcher(sc.poll, watchDirs...)
if err != nil {
return err
}