mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-26 21:01:24 +02:00
Auto-reload config file on RENAME
Some editors (like Vim), create a temp file when saving, then replace the file being edited with the temp file. This causes the FS notify event to be RENAME, not WRITE, so auto-reload misses this. In addition to that, the file is removed from the watcher and the auto-reload functionality stops working entirely after the first RENAME. https://github.com/fsnotify/fsnotify/issues/255 describes this.
This commit is contained in:
parent
d8a4d39849
commit
f7f333ad52
@ -286,6 +286,20 @@ func configFilesWatcher(
|
|||||||
}
|
}
|
||||||
if event.Has(fsnotify.Write) {
|
if event.Has(fsnotify.Write) {
|
||||||
debouncedCallback()
|
debouncedCallback()
|
||||||
|
} else if event.Has(fsnotify.Rename) {
|
||||||
|
// wait for file to be available
|
||||||
|
for i := 0; i < 20; i++ {
|
||||||
|
_, err := os.Stat(mainFileAbsPath)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
err := watcher.Add(mainFileAbsPath)
|
||||||
|
if err != nil {
|
||||||
|
onErr(fmt.Errorf("watching file:", err))
|
||||||
|
}
|
||||||
|
debouncedCallback()
|
||||||
} else if event.Has(fsnotify.Remove) {
|
} else if event.Has(fsnotify.Remove) {
|
||||||
func() {
|
func() {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user