From 5c5158b3c1275a11b66687496706372c01f66817 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Thu, 5 May 2022 03:28:41 +0200 Subject: [PATCH] store: remove callbacks on error Unmark deleted messages and remove pending headers in the callback function when an error in the backend occurs (e.g. due to connection issues). The message store marks messages that should be deleted. If the delete operation in the backend fails, messages are never unmarked and will remain rendered as empty lines in the message list. This also affects the move and archive commands that rely on a copy and delete operation. A similar issue occurs with the pending headers when the operation to fetch them fails. In this case, messages will appear as loading indefinitely in the message list and are never re-fetched because the corresponding pending headers from the failed operations are still present. Fixes: https://todo.sr.ht/~rjarry/aerc/28 Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/msgstore.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/msgstore.go b/lib/msgstore.go index a5c0e8f..908f125 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -111,7 +111,15 @@ func (store *MessageStore) FetchHeaders(uids []uint32, } } if len(toFetch) > 0 { - store.worker.PostAction(&types.FetchMessageHeaders{Uids: toFetch}, nil) + store.worker.PostAction(&types.FetchMessageHeaders{Uids: toFetch}, func(msg types.WorkerMessage) { + switch msg.(type) { + case *types.Error: + for _, uid := range toFetch { + delete(store.pendingHeaders, uid) + delete(store.headerCallbacks, uid) + } + } + }) } } @@ -139,6 +147,7 @@ func (store *MessageStore) FetchFull(uids []uint32, cb func(*types.FullMessage)) switch msg.(type) { case *types.Error: for _, uid := range toFetch { + delete(store.pendingBodies, uid) delete(store.bodyCallbacks, uid) } } @@ -389,10 +398,25 @@ func (store *MessageStore) Delete(uids []uint32, store.Deleted[uid] = nil } - store.worker.PostAction(&types.DeleteMessages{Uids: uids}, cb) + store.worker.PostAction(&types.DeleteMessages{Uids: uids}, + func(msg types.WorkerMessage) { + switch msg.(type) { + case *types.Error: + store.revertDeleted(uids) + } + cb(msg) + }) store.update() } +func (store *MessageStore) revertDeleted(uids []uint32) { + for _, uid := range uids { + if _, ok := store.Deleted[uid]; ok { + delete(store.Deleted, uid) + } + } +} + func (store *MessageStore) Copy(uids []uint32, dest string, createDest bool, cb func(msg types.WorkerMessage)) { @@ -429,9 +453,10 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool, }, func(msg types.WorkerMessage) { switch msg.(type) { case *types.Error: + store.revertDeleted(uids) cb(msg) case *types.Done: - store.worker.PostAction(&types.DeleteMessages{Uids: uids}, cb) + store.Delete(uids, cb) } })