Skip to content

Commit

Permalink
Fix watching additional paths, correct events on Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arp242 committed Jan 16, 2022
1 parent 9239a69 commit b28a549
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"math"
"os"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down

0 comments on commit b28a549

Please sign in to comment.