Skip to content

Commit

Permalink
all: add & use empty fswatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jun 14, 2024
1 parent 8432593 commit e033558
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-->
Expand Down
27 changes: 27 additions & 0 deletions internal/aghos/fswatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e033558

Please sign in to comment.