From 91c6bac61f93f04e22a91867fec78d0e26880bb6 Mon Sep 17 00:00:00 2001 From: prateek-narsinghani Date: Fri, 5 Apr 2024 23:56:49 +0530 Subject: [PATCH] not creating multiple watcher for single file path --- providers/file/file.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/providers/file/file.go b/providers/file/file.go index 28521c3..d9062b4 100644 --- a/providers/file/file.go +++ b/providers/file/file.go @@ -37,6 +37,11 @@ func (f *File) Read() (map[string]interface{}, error) { // Watch watches the file and triggers a callback when it changes. It is a // blocking function that internally spawns a goroutine to watch for changes. func (f *File) Watch(cb func(event interface{}, err error)) error { + // If a watcher already exists, return an error. + if f.w != nil { + return errors.New("watcher already exists") + } + // Resolve symlinks and save the original path so that changes to symlinks // can be detected. realPath, err := filepath.EvalSymlinks(f.path)