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 <robin@jarry.cc>
This commit is contained in:
parent
f776fb8246
commit
f4d3c8fc77
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue