Skip to content

Commit

Permalink
check watched file
Browse files Browse the repository at this point in the history
  • Loading branch information
jinja2 committed Nov 20, 2024
1 parent 9bc2b07 commit c2a2af8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/configsource/includeconfigsource/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func newConfigSource(config *Config) (configsource.ConfigSource, error) {
}

func (is *includeConfigSource) Retrieve(_ context.Context, selector string, paramsConfigMap *confmap.Conf, watcher confmap.WatcherFunc) (*confmap.Retrieved, error) {
fmt.Println("Selector: ", selector)

tmpl, err := template.ParseFiles(selector)
if err != nil {
return nil, err
Expand All @@ -79,6 +81,7 @@ func (is *includeConfigSource) Retrieve(_ context.Context, selector string, para
return confmap.NewRetrieved(buf.String())
}

fmt.Println("Creating watch for file: ", selector)
closeFunc, err := is.watchFile(selector, watcher)
if err != nil {
return nil, err
Expand Down Expand Up @@ -108,6 +111,7 @@ func (is *includeConfigSource) watchFile(file string, watcherFunc confmap.Watche
return
}
if event.Op&fsnotify.Write == fsnotify.Write {
fmt.Println("File modified: ", event.Name)
watcherFunc(&confmap.ChangeEvent{Error: nil})
return
}
Expand All @@ -127,6 +131,8 @@ func (is *includeConfigSource) watchFile(file string, watcherFunc confmap.Watche
return nil, err
}

fmt.Println("watcher added entries:", is.watcher.WatchList())

is.watchedFiles[file] = struct{}{}

return func(_ context.Context) error {
Expand All @@ -135,6 +141,7 @@ func (is *includeConfigSource) watchFile(file string, watcherFunc confmap.Watche
return err
}
if len(is.watcher.WatchList()) == 0 {
fmt.Println("watch closed")
return is.watcher.Close()
}
return nil
Expand Down

0 comments on commit c2a2af8

Please sign in to comment.