From f8dc87cb36616725cfcdb6524025c736d67cdc66 Mon Sep 17 00:00:00 2001 From: Michael James Gratton Date: Tue, 28 Nov 2017 17:40:15 +1100 Subject: [PATCH] Ensure EmailStore always closes folders when executing an operation. --- src/engine/app/app-email-store.vala | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/engine/app/app-email-store.vala b/src/engine/app/app-email-store.vala index 312c829d..4390dfae 100644 --- a/src/engine/app/app-email-store.vala +++ b/src/engine/app/app-email-store.vala @@ -181,30 +181,31 @@ public class Geary.App.EmailStore : BaseObject { try { debug("EmailStore opening %s for %s on %d emails", folder.to_string(), operation.get_type().name(), ids.size); - + yield folder.open_async(Geary.Folder.OpenFlags.FAST_OPEN, cancellable); open = true; - used_ids = yield operation.execute_async(folder, ids, cancellable); - - yield folder.close_async(cancellable); - open = false; - - debug("EmailStore closed %s after %s on %d emails", folder.to_string(), - operation.get_type().name(), ids.size); } catch (Error e) { debug("Error performing an operation on messages in %s: %s", folder.to_string(), e.message); - + } finally { if (open) { try { - yield folder.close_async(cancellable); - open = false; + // Don't use the cancellable here, if it's been + // opened we need to try to close it. + yield folder.close_async(null); + debug( + "EmailStore closed %s after %s on %d emails", + folder.to_string(), + operation.get_type().name(), + ids.size + ); } catch (Error e) { - debug("Error closing folder %s: %s", folder.to_string(), e.message); + debug("Error closing folder %s: %s", + folder.to_string(), e.message); } } } - + // We don't want to operate on any mails twice. if (used_ids != null) { foreach (Geary.EmailIdentifier id in used_ids.to_array()) {