Skip to content

Commit

Permalink
protect multiple watches
Browse files Browse the repository at this point in the history
  • Loading branch information
steviebps committed Sep 12, 2021
1 parent b819811 commit b8f56c8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/rein.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type config struct {
configPaths []string
defaultVersion string
configFileUsed string
isWatching bool
}

var c *config
Expand Down Expand Up @@ -115,9 +116,13 @@ func (cfg *config) Watch() error {
return errors.New("a config file was not successfully read so it cannot be watched")
}

if cfg.isWatching {
return errors.New("config is already being watched")
}

watcher, err := fsnotify.NewWatcher()
if err != nil {
return errors.New("could not establish file watcher")
return fmt.Errorf("could not establish file watcher: %w", err)
}
// TODO: establish a way to end the file watching and close the watcher
// defer watcher.Close()
Expand Down Expand Up @@ -146,6 +151,7 @@ func (cfg *config) Watch() error {
if err != nil {
return fmt.Errorf("could not establish file watcher with file: %q", cfg.configFileUsed)
}
cfg.isWatching = true

return nil
}
Expand Down

0 comments on commit b8f56c8

Please sign in to comment.