Skip to content

Commit

Permalink
Merge pull request #3 from msokk/fix-darwin
Browse files Browse the repository at this point in the history
Workaround fix for reloading on macOS
  • Loading branch information
arp242 committed Sep 1, 2018
2 parents 71ac78c + 26c6548 commit 9285b66
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -58,7 +59,20 @@ func Do(log func(string, ...interface{})) error {
// Panic, and Fatal :-/ Printf() is probably best.
log("reload error: %v", err)
case event := <-watcher.Events:
if event.Op&fsnotify.Write == fsnotify.Write && event.Name == bin {
// 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)
}

if trigger && event.Name == bin {
// Wait for writes to finish.
time.Sleep(100 * time.Millisecond)
exec(bin)
Expand Down

0 comments on commit 9285b66

Please sign in to comment.