aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/watchers/inotify.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-06-29 16:53:38 +0200
committerRobin Jarry <robin@jarry.cc>2023-08-04 11:32:40 +0200
commita3e811e00d8a7fe0f37d85557d7db60087967171 (patch)
treefc5e3e35487499e9b78a3f4f875f8bfb8f807526 /worker/lib/watchers/inotify.go
parentd29c9d1a2ff82234ad1810abc6a57199340e7fd5 (diff)
downloadaerc-a3e811e00d8a7fe0f37d85557d7db60087967171.tar.gz
watchers: move filesystem monitoring stuff in lib
No functional change. This will allow reuse in other parts of aerc. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'worker/lib/watchers/inotify.go')
-rw-r--r--worker/lib/watchers/inotify.go76
1 files changed, 0 insertions, 76 deletions
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)
-}