all: add & use empty fswatcher

This commit is contained in:
Eugene Burkov 2024-06-14 14:39:58 +03:00
parent 8432593be1
commit e033558d70
3 changed files with 35 additions and 1 deletions

View File

@ -35,6 +35,11 @@ NOTE: Add new changes BELOW THIS COMMENT.
- Node 18 support, Node 20 will be required in future releases.
### Fixed
- Tracking `/etc/hosts` file changes causing panics within particular
filesystems on start ([#7076]).
<!--
NOTE: Add new changes ABOVE THIS COMMENT.
-->

View File

@ -160,3 +160,30 @@ func (w *osWatcher) handleErrors() {
log.Error("%s: %s", osWatcherPref, err)
}
}
// EmptyFSWatcher is a no-op implementation of the [FSWatcher] interface. It
// may be used on systems not supporting filesystem events.
type EmptyFSWatcher struct{}
// type check
var _ FSWatcher = EmptyFSWatcher{}
// Start implements the [FSWatcher] interface for EmptyFSWatcher.
func (EmptyFSWatcher) Start() (err error) {
return nil
}
// Close implements the [FSWatcher] interface for EmptyFSWatcher.
func (EmptyFSWatcher) Close() (err error) {
return nil
}
// Events implements the [FSWatcher] interface for EmptyFSWatcher.
func (EmptyFSWatcher) Events() (e <-chan event) {
return nil
}
// Add implements the [FSWatcher] interface for EmptyFSWatcher.
func (EmptyFSWatcher) Add(_ string) (err error) {
return nil
}

View File

@ -232,7 +232,9 @@ func configureOS(conf *configuration) (err error) {
func setupHostsContainer() (err error) {
hostsWatcher, err := aghos.NewOSWritesWatcher()
if err != nil {
return fmt.Errorf("initing hosts watcher: %w", err)
log.Info("WARNING: initializing filesystem watcher: %s; not watching for changes", err)
hostsWatcher = aghos.EmptyFSWatcher{}
}
paths, err := hostsfile.DefaultHostsPaths()