From f4d3c8fc77f97c1c01e85329c54c522c2cfd13bb Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 6 Dec 2021 20:42:07 +0100 Subject: maildir: watch for external changes When a maildir is synchronized by an external process while aerc is running (e.g. mbsync), some emails may be moved out of "new" to "cur" or completely deleted. These deletions are ignored and aerc may assume these messages are still here, leading to errors. Take file deletions into account. Also, add "cur" to the watched folders since these can be modified as well. Signed-off-by: Robin Jarry --- worker/maildir/worker.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'worker/maildir') diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 5888f11..099a85c 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -71,8 +71,8 @@ func (w *Worker) handleAction(action types.WorkerMessage) { } func (w *Worker) handleFSEvent(ev fsnotify.Event) { - // we only care about files being created - if ev.Op != fsnotify.Create { + // we only care about files being created or removed + if ev.Op != fsnotify.Create && ev.Op != fsnotify.Remove { return } // if there's not a selected directory to rescan, ignore @@ -275,22 +275,30 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { return err } - // remove existing watch path + // remove existing watch paths if w.selected != nil { prevDir := filepath.Join(string(*w.selected), "new") if err := w.watcher.Remove(prevDir); err != nil { return fmt.Errorf("could not unwatch previous directory: %v", err) } + prevDir = filepath.Join(string(*w.selected), "cur") + if err := w.watcher.Remove(prevDir); err != nil { + return fmt.Errorf("could not unwatch previous directory: %v", err) + } } w.selected = &dir w.selectedName = msg.Directory - // add watch path + // add watch paths newDir := filepath.Join(string(*w.selected), "new") if err := w.watcher.Add(newDir); err != nil { return fmt.Errorf("could not add watch to directory: %v", err) } + newDir = filepath.Join(string(*w.selected), "cur") + if err := w.watcher.Add(newDir); err != nil { + return fmt.Errorf("could not add watch to directory: %v", err) + } if err := dir.Clean(); err != nil { return fmt.Errorf("could not clean directory: %v", err) -- cgit v1.2.3