From b28a549160364ca6b160569264797f7ccff556a2 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sun, 16 Jan 2022 07:02:38 +0100 Subject: [PATCH] Fix watching additional paths, correct events on Linux This fixes two things: - A regression from #11 which caused the "additional paths" to break because it was no longer set to the fill path. - On my Linux machine there is no longer a "WRITE" event, only a CREATE event: Name Op trigger /home/martin/.local/gobin/goatcounter-go-tmp-umask REMOVE false /home/martin/.local/gobin/goatcounter CREATE true I don't know if this is due to a change in Go or Linux, but checking both on all platforms is probably the safest anyway. --- reload.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/reload.go b/reload.go index 9b3f34e..80c3a6d 100644 --- a/reload.go +++ b/reload.go @@ -30,7 +30,6 @@ import ( "math" "os" "path/filepath" - "runtime" "strings" "syscall" "time" @@ -101,7 +100,7 @@ func Do(log func(string, ...interface{}), additional ...dir) error { a.path) } - a.path = path + additional[i].path = path dirs[i+1] = path timers[path] = stoppedTimer(a.cb) } @@ -115,19 +114,7 @@ func Do(log func(string, ...interface{}), additional ...dir) error { log("reload error: %v", err) } case event := <-watcher.Events: - // Ensure that we use the correct events, as they are not uniform accross - // platforms. See https://github.com/fsnotify/fsnotify/issues/74 - var trigger bool - switch runtime.GOOS { - case "darwin", "freebsd", "openbsd", "netbsd", "dragonfly": - trigger = event.Op&fsnotify.Create == fsnotify.Create - case "linux": - trigger = event.Op&fsnotify.Write == fsnotify.Write - default: - trigger = event.Op&fsnotify.Create == fsnotify.Create - log("reload: untested GOOS %q; this package may not work correctly", runtime.GOOS) - } - + trigger := (event.Op&fsnotify.Write == fsnotify.Write) || (event.Op&fsnotify.Create == fsnotify.Create) if !trigger { continue }