Skip to content

Commit

Permalink
Fix to support hot reload with vim editor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpesin committed Sep 12, 2017
1 parent cfd138c commit 142e912
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"strings"
"time"

"github.com/adnanh/webhook/hook"

Expand Down Expand Up @@ -427,10 +428,13 @@ func watchForFileChange() {
log.Printf("hooks file %s modified\n", event.Name)
reloadHooks(event.Name)
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
log.Printf("hooks file %s removed, no longer watching this file for changes, removing hooks that were loaded from it\n", event.Name)
(*watcher).Remove(event.Name)
removeHooks(event.Name)
if _, err := os.Stat(event.Name); os.IsNotExist(err) {
log.Printf("hooks file %s removed, no longer watching this file for changes, removing hooks that were loaded from it\n", event.Name)
(*watcher).Remove(event.Name)
removeHooks(event.Name)
}
} else if event.Op&fsnotify.Rename == fsnotify.Rename {
time.Sleep(100 * time.Millisecond)
if _, err := os.Stat(event.Name); os.IsNotExist(err) {
// file was removed
log.Printf("hooks file %s removed, no longer watching this file for changes, and removing hooks that were loaded from it\n", event.Name)
Expand All @@ -440,6 +444,8 @@ func watchForFileChange() {
// file was overwritten
log.Printf("hooks file %s overwritten\n", event.Name)
reloadHooks(event.Name)
(*watcher).Remove(event.Name)
(*watcher).Add(event.Name)
}
}
case err := <-(*watcher).Errors:
Expand Down

0 comments on commit 142e912

Please sign in to comment.