v0.18.1 file watcher retirement diagnostics update

This commit is contained in:
2026-09-13 18:53:18 -04:00
parent 5934a2e35f
commit 7b782a79ef
10 changed files with 169 additions and 28 deletions
+12 -4
View File
@@ -292,12 +292,21 @@ func (fs *FileSource) ensureWatcher(path string) {
}
}
fs.mu.Lock()
delete(fs.watchers, path)
fs.mu.Unlock()
fs.removeWatcher(path, w)
}()
}
// removeWatcher removes only the watcher that finished. A deleted file can be
// recreated before its old watcher observes stop; in that case ensureWatcher
// has already installed a replacement under the same path, which must survive.
func (fs *FileSource) removeWatcher(path string, watcher *fileWatcher) {
fs.mu.Lock()
if fs.watchers[path] == watcher {
delete(fs.watchers, path)
}
fs.mu.Unlock()
}
// cleanupWatchers stops and removes watchers for files that no longer exist.
func (fs *FileSource) cleanupWatchers() {
fs.mu.Lock()
@@ -369,4 +378,3 @@ func globToRegex(glob string) string {
regex = strings.ReplaceAll(regex, `\?`, `.`)
return "^" + regex + "$"
}