@@ -12,6 +12,7 @@ import (
1212 "os"
1313 "path/filepath"
1414 "regexp"
15+ "slices"
1516 "strings"
1617 "sync"
1718 "sync/atomic"
@@ -136,14 +137,18 @@ func (fws *FileWatcherService) addWatchers(ctx context.Context) {
136137 continue
137138 }
138139
139- fws .addWatcher (ctx , directory )
140+ if ! slices .Contains (fws .watcher .WatchList (), directory ) {
141+ fws .addWatcher (ctx , directory )
142+ fws .filesChanged .Store (true )
143+ }
140144 }
141145}
142146
143147func (fws * FileWatcherService ) removeWatchers (ctx context.Context ) {
144148 for _ , directoryBeingWatched := range fws .watcher .WatchList () {
145149 if _ , ok := fws .directoriesToWatch [directoryBeingWatched ]; ! ok {
146150 fws .removeWatcher (ctx , directoryBeingWatched )
151+ fws .filesChanged .Store (true )
147152 }
148153 }
149154}
@@ -202,11 +207,6 @@ func (fws *FileWatcherService) addWatcher(ctx context.Context, directory string)
202207 ctx , "Unable to watch directory that does not exist" ,
203208 "directory" , directory , "error" , err ,
204209 )
205-
206- removeError := fws .watcher .Remove (directory )
207- if removeError != nil {
208- slog .WarnContext (ctx , "Failed to remove file watcher" , "directory_path" , directory , "error" , removeError )
209- }
210210 }
211211
212212 slog .DebugContext (ctx , "Adding watcher" , "directory" , directory )
0 commit comments