summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-05-05 03:28:41 +0200
committerRobin Jarry <robin@jarry.cc>2022-05-06 11:02:33 +0200
commit5c5158b3c1275a11b66687496706372c01f66817 (patch)
treee4a1b60b8f05da88bb972a2805ac35645e37ac3e
parentad51cb3611d0799a5cef03083f20b6b85c795f23 (diff)
downloadaerc-5c5158b3c1275a11b66687496706372c01f66817.tar.gz
aerc-5c5158b3c1275a11b66687496706372c01f66817.zip
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 <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/msgstore.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index a5c0e8f5..908f125e 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)
}
})