From 98b4b7330ec2703be8aac979477c42c6738b06b2 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 30 Nov 2024 12:23:57 +0000 Subject: [PATCH] Further fixes for config file watcher --- internal/glance/config.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/glance/config.go b/internal/glance/config.go index f69f1a3..8322dbf 100644 --- a/internal/glance/config.go +++ b/internal/glance/config.go @@ -5,6 +5,7 @@ import ( "fmt" "html/template" "log" + "maps" "os" "path/filepath" "regexp" @@ -202,9 +203,13 @@ func configFilesWatcher( mu.Lock() defer mu.Unlock() - if !bytes.Equal(lastContents, currentContents) { + if !maps.Equal(currentIncludes, lastIncludes) { updateWatchedIncludes(lastIncludes, currentIncludes) - lastContents, lastIncludes = currentContents, currentIncludes + lastIncludes = currentIncludes + } + + if !bytes.Equal(lastContents, currentContents) { + lastContents = currentContents onChange(currentContents) } } @@ -230,9 +235,12 @@ func configFilesWatcher( if event.Has(fsnotify.Write) { debouncedCallback() } else if event.Has(fsnotify.Remove) { - mu.Lock() - delete(lastIncludes, event.Name) - mu.Unlock() + func() { + mu.Lock() + defer mu.Unlock() + fileAbsPath, _ := filepath.Abs(event.Name) + delete(lastIncludes, fileAbsPath) + }() debouncedCallback() }