aboutsummaryrefslogtreecommitdiffstats
path: root/worker/maildir
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-03-02 16:46:01 -0600
committerRobin Jarry <robin@jarry.cc>2023-03-07 16:37:02 +0100
commit261c388c7325f07efb58afe97ddcf83e6fa99ce7 (patch)
tree238b7346fd8e6b250e8d66bf3255e07e7832b9e6 /worker/maildir
parenta0935a3de0cec483a605df5017307f50a186f5cb (diff)
downloadaerc-261c388c7325f07efb58afe97ddcf83e6fa99ce7.tar.gz
maildir: use FSWatcher interface
Use the FSWatcher interface to create the watcher. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Ben Lee-Cohen <ben@lee-cohen.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/maildir')
-rw-r--r--worker/maildir/worker.go18
1 files changed, 5 insertions, 13 deletions
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index a8ed0b50..11bab4ea 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -16,7 +16,6 @@ import (
"sync"
"github.com/emersion/go-maildir"
- "github.com/fsnotify/fsnotify"
aercLib "git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/iterator"
@@ -40,14 +39,14 @@ type Worker struct {
selected *maildir.Dir
selectedName string
worker *types.Worker
- watcher *fsnotify.Watcher
+ watcher types.FSWatcher
currentSortCriteria []*types.SortCriterion
maildirpp bool // whether to use Maildir++ directory layout
}
// NewWorker creates a new maildir worker with the provided worker.
func NewWorker(worker *types.Worker) (types.Backend, error) {
- watch, err := fsnotify.NewWatcher()
+ watch, err := handlers.NewWatcher()
if err != nil {
return nil, fmt.Errorf("could not create file system watcher: %w", err)
}
@@ -56,7 +55,7 @@ func NewWorker(worker *types.Worker) (types.Backend, error) {
// NewMaildirppWorker creates a new Maildir++ worker with the provided worker.
func NewMaildirppWorker(worker *types.Worker) (types.Backend, error) {
- watch, err := fsnotify.NewWatcher()
+ watch, err := handlers.NewWatcher()
if err != nil {
return nil, fmt.Errorf("could not create file system watcher: %w", err)
}
@@ -69,7 +68,7 @@ func (w *Worker) Run() {
select {
case action := <-w.worker.Actions:
w.handleAction(action)
- case ev := <-w.watcher.Events:
+ case ev := <-w.watcher.Events():
w.handleFSEvent(ev)
}
}
@@ -101,14 +100,7 @@ func (w *Worker) handleAction(action types.WorkerMessage) {
}
}
-func (w *Worker) handleFSEvent(ev fsnotify.Event) {
- // we only care about files being created, removed or renamed
- switch ev.Op {
- case fsnotify.Create, fsnotify.Remove, fsnotify.Rename:
- break
- default:
- return
- }
+func (w *Worker) handleFSEvent(ev *types.FSEvent) {
// if there's not a selected directory to rescan, ignore
if w.selected == nil {
return