diff options
Diffstat (limited to 'worker/lib')
-rw-r--r-- | worker/lib/watchers/fsevents.go | 84 | ||||
-rw-r--r-- | worker/lib/watchers/inotify.go | 76 |
2 files changed, 0 insertions, 160 deletions
diff --git a/worker/lib/watchers/fsevents.go b/worker/lib/watchers/fsevents.go deleted file mode 100644 index 7b657999..00000000 --- a/worker/lib/watchers/fsevents.go +++ /dev/null @@ -1,84 +0,0 @@ -//go:build darwin -// +build darwin - -package watchers - -import ( - "time" - - "git.sr.ht/~rjarry/aerc/log" - "git.sr.ht/~rjarry/aerc/worker/handlers" - "git.sr.ht/~rjarry/aerc/worker/types" - "github.com/fsnotify/fsevents" -) - -func init() { - handlers.RegisterWatcherFactory(newDarwinWatcher) -} - -type darwinWatcher struct { - ch chan *types.FSEvent - w *fsevents.EventStream - watcherCh chan []fsevents.Event -} - -func newDarwinWatcher() (types.FSWatcher, error) { - watcher := &darwinWatcher{ - watcherCh: make(chan []fsevents.Event), - ch: make(chan *types.FSEvent), - w: &fsevents.EventStream{ - Flags: fsevents.FileEvents | fsevents.WatchRoot, - Latency: 500 * time.Millisecond, - }, - } - return watcher, nil -} - -func (w *darwinWatcher) watch() { - defer log.PanicHandler() - for events := range w.w.Events { - for _, ev := range events { - switch { - case ev.Flags&fsevents.ItemCreated > 0: - w.ch <- &types.FSEvent{ - Operation: types.FSCreate, - Path: ev.Path, - } - case ev.Flags&fsevents.ItemRenamed > 0: - w.ch <- &types.FSEvent{ - Operation: types.FSRename, - Path: ev.Path, - } - case ev.Flags&fsevents.ItemRemoved > 0: - w.ch <- &types.FSEvent{ - Operation: types.FSRemove, - Path: ev.Path, - } - } - } - } -} - -func (w *darwinWatcher) Configure(root string) error { - dev, err := fsevents.DeviceForPath(root) - if err != nil { - return err - } - w.w.Device = dev - w.w.Paths = []string{root} - w.w.Start() - go w.watch() - return nil -} - -func (w *darwinWatcher) Events() chan *types.FSEvent { - return w.ch -} - -func (w *darwinWatcher) Add(p string) error { - return nil -} - -func (w *darwinWatcher) Remove(p string) error { - return nil -} diff --git a/worker/lib/watchers/inotify.go b/worker/lib/watchers/inotify.go deleted file mode 100644 index 027ef4f2..00000000 --- a/worker/lib/watchers/inotify.go +++ /dev/null @@ -1,76 +0,0 @@ -//go:build !darwin -// +build !darwin - -package watchers - -import ( - "git.sr.ht/~rjarry/aerc/log" - "git.sr.ht/~rjarry/aerc/worker/handlers" - "git.sr.ht/~rjarry/aerc/worker/types" - "github.com/fsnotify/fsnotify" -) - -func init() { - handlers.RegisterWatcherFactory(newInotifyWatcher) -} - -type inotifyWatcher struct { - w *fsnotify.Watcher - ch chan *types.FSEvent -} - -func newInotifyWatcher() (types.FSWatcher, error) { - watcher := &inotifyWatcher{ - ch: make(chan *types.FSEvent), - } - w, err := fsnotify.NewWatcher() - if err != nil { - return nil, err - } - watcher.w = w - - go watcher.watch() - return watcher, nil -} - -func (w *inotifyWatcher) watch() { - defer log.PanicHandler() - for ev := range w.w.Events { - // we only care about files being created, removed or renamed - switch ev.Op { - case fsnotify.Create: - w.ch <- &types.FSEvent{ - Operation: types.FSCreate, - Path: ev.Name, - } - case fsnotify.Remove: - w.ch <- &types.FSEvent{ - Operation: types.FSRemove, - Path: ev.Name, - } - case fsnotify.Rename: - w.ch <- &types.FSEvent{ - Operation: types.FSRename, - Path: ev.Name, - } - default: - continue - } - } -} - -func (w *inotifyWatcher) Configure(root string) error { - return w.w.Add(root) -} - -func (w *inotifyWatcher) Events() chan *types.FSEvent { - return w.ch -} - -func (w *inotifyWatcher) Add(p string) error { - return w.w.Add(p) -} - -func (w *inotifyWatcher) Remove(p string) error { - return w.w.Remove(p) -} |