mirror of
https://github.com/Xevion/glance.git
synced 2025-12-10 06:07:20 -06:00
Somewhat working fix for config watcher
This commit is contained in:
@@ -189,6 +189,9 @@ func configFilesWatcher(
|
|||||||
|
|
||||||
updateWatchedIncludes(nil, lastIncludes)
|
updateWatchedIncludes(nil, lastIncludes)
|
||||||
|
|
||||||
|
// needed for lastContents and lastIncludes because they get updated in multiple goroutines
|
||||||
|
mu := sync.Mutex{}
|
||||||
|
|
||||||
checkForContentChangesBeforeCallback := func() {
|
checkForContentChangesBeforeCallback := func() {
|
||||||
currentContents, currentIncludes, err := parseYAMLIncludes(mainFilePath)
|
currentContents, currentIncludes, err := parseYAMLIncludes(mainFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -196,6 +199,9 @@ func configFilesWatcher(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
|
||||||
if !bytes.Equal(lastContents, currentContents) {
|
if !bytes.Equal(lastContents, currentContents) {
|
||||||
updateWatchedIncludes(lastIncludes, currentIncludes)
|
updateWatchedIncludes(lastIncludes, currentIncludes)
|
||||||
lastContents, lastIncludes = currentContents, currentIncludes
|
lastContents, lastIncludes = currentContents, currentIncludes
|
||||||
@@ -223,17 +229,13 @@ func configFilesWatcher(
|
|||||||
}
|
}
|
||||||
if event.Has(fsnotify.Write) {
|
if event.Has(fsnotify.Write) {
|
||||||
debouncedCallback()
|
debouncedCallback()
|
||||||
}
|
} else if event.Has(fsnotify.Remove) {
|
||||||
// maybe also handle .Remove event?
|
mu.Lock()
|
||||||
// from testing it appears that a removed file will stop triggering .Write events
|
delete(lastIncludes, event.Name)
|
||||||
// when it gets recreated, in which case we may need to watch the directory for the
|
mu.Unlock()
|
||||||
// creation of that file and then re-add it to the watcher, though that's
|
|
||||||
// a lot of effort for a hopefully rare edge case
|
|
||||||
|
|
||||||
// TODO: update - try and fix this for v0.7.0
|
debouncedCallback()
|
||||||
// so, about that "rare edge case"... it's not so rare
|
}
|
||||||
// guess what happens when you run `git pull` and a file has changes?
|
|
||||||
// yeah, it gets removed and re-added ( :
|
|
||||||
case err, isOpen := <-watcher.Errors:
|
case err, isOpen := <-watcher.Errors:
|
||||||
if !isOpen {
|
if !isOpen {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user