mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-08-17 06:30:37 +03:00
Pull request 2239: 7076 Empty FSWatcher
Updates #7076. Squashed commit of the following: commit6d99de9bcd
Merge:c545152fa
1c82be295
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jun 17 18:41:49 2024 +0300 Merge branch 'master' into 7076-empty-fswatcher commitc545152fa1
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jun 14 14:57:01 2024 +0300 all: imp code commite033558d70
Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jun 14 14:39:58 2024 +0300 all: add & use empty fswatcher
This commit is contained in:
parent
1c82be2950
commit
66877c92d9
@ -49,6 +49,11 @@ NOTE: Add new changes BELOW THIS COMMENT.
|
|||||||
|
|
||||||
- Node 18 support, Node 20 will be required in future releases.
|
- 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]).
|
||||||
|
|
||||||
[#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053
|
[#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053
|
||||||
|
|
||||||
[install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac
|
[install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac
|
||||||
|
@ -161,7 +161,8 @@ func (hc *HostsContainer) handleEvents() {
|
|||||||
|
|
||||||
defer close(hc.updates)
|
defer close(hc.updates)
|
||||||
|
|
||||||
ok, eventsCh := true, hc.watcher.Events()
|
eventsCh := hc.watcher.Events()
|
||||||
|
ok := eventsCh != nil
|
||||||
for ok {
|
for ok {
|
||||||
select {
|
select {
|
||||||
case _, ok = <-eventsCh:
|
case _, ok = <-eventsCh:
|
||||||
|
@ -160,3 +160,34 @@ func (w *osWatcher) handleErrors() {
|
|||||||
log.Error("%s: %s", osWatcherPref, err)
|
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. It always
|
||||||
|
// returns nil error.
|
||||||
|
func (EmptyFSWatcher) Start() (err error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close implements the [FSWatcher] interface for EmptyFSWatcher. It always
|
||||||
|
// returns nil error.
|
||||||
|
func (EmptyFSWatcher) Close() (err error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Events implements the [FSWatcher] interface for EmptyFSWatcher. It always
|
||||||
|
// returns nil channel.
|
||||||
|
func (EmptyFSWatcher) Events() (e <-chan event) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add implements the [FSWatcher] interface for EmptyFSWatcher. It always
|
||||||
|
// returns nil error.
|
||||||
|
func (EmptyFSWatcher) Add(_ string) (err error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -232,7 +232,9 @@ func configureOS(conf *configuration) (err error) {
|
|||||||
func setupHostsContainer() (err error) {
|
func setupHostsContainer() (err error) {
|
||||||
hostsWatcher, err := aghos.NewOSWritesWatcher()
|
hostsWatcher, err := aghos.NewOSWritesWatcher()
|
||||||
if err != nil {
|
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()
|
paths, err := hostsfile.DefaultHostsPaths()
|
||||||
|
Loading…
Reference in New Issue
Block a user