mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-30 09:12:28 +00:00
Merge pull request #172 from ivanpesin/fsnotify-vim
Fix to support hot reload with vim editor changes
This commit is contained in:
commit
985d5197ed
1 changed files with 9 additions and 3 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/adnanh/webhook/hook"
|
"github.com/adnanh/webhook/hook"
|
||||||
|
|
||||||
|
@ -427,10 +428,13 @@ func watchForFileChange() {
|
||||||
log.Printf("hooks file %s modified\n", event.Name)
|
log.Printf("hooks file %s modified\n", event.Name)
|
||||||
reloadHooks(event.Name)
|
reloadHooks(event.Name)
|
||||||
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
|
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
|
||||||
|
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)
|
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)
|
(*watcher).Remove(event.Name)
|
||||||
removeHooks(event.Name)
|
removeHooks(event.Name)
|
||||||
|
}
|
||||||
} else if event.Op&fsnotify.Rename == fsnotify.Rename {
|
} else if event.Op&fsnotify.Rename == fsnotify.Rename {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
if _, err := os.Stat(event.Name); os.IsNotExist(err) {
|
if _, err := os.Stat(event.Name); os.IsNotExist(err) {
|
||||||
// file was removed
|
// 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)
|
log.Printf("hooks file %s removed, no longer watching this file for changes, and removing hooks that were loaded from it\n", event.Name)
|
||||||
|
@ -440,6 +444,8 @@ func watchForFileChange() {
|
||||||
// file was overwritten
|
// file was overwritten
|
||||||
log.Printf("hooks file %s overwritten\n", event.Name)
|
log.Printf("hooks file %s overwritten\n", event.Name)
|
||||||
reloadHooks(event.Name)
|
reloadHooks(event.Name)
|
||||||
|
(*watcher).Remove(event.Name)
|
||||||
|
(*watcher).Add(event.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case err := <-(*watcher).Errors:
|
case err := <-(*watcher).Errors:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue