From 7c6aa944e224b4f938cad03bc6531bc5430c9cdb Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 1 Jul 2011 20:01:45 +0200 Subject: Bug #650671 - Service connect/disconnect not cancelled properly --- mail/e-mail-session-utils.c | 10 ++++---- mail/e-mail-session.c | 4 ++-- mail/e-mail-store-utils.c | 6 +++-- mail/em-folder-utils.c | 6 ++--- mail/em-utils.c | 49 ++++++++++++++++++++++++++++++++++++++++ mail/em-utils.h | 3 +++ mail/mail-ops.c | 8 +++---- mail/mail-vfolder.c | 2 +- modules/mail/e-mail-shell-view.c | 4 ++-- 9 files changed, 74 insertions(+), 18 deletions(-) diff --git a/mail/e-mail-session-utils.c b/mail/e-mail-session-utils.c index 4e90a19ecf..823852ed21 100644 --- a/mail/e-mail-session-utils.c +++ b/mail/e-mail-session-utils.c @@ -22,6 +22,8 @@ #include "e-mail-session-utils.h" +#include "em-utils.h" + #include #include @@ -423,7 +425,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple, did_connect = TRUE; /* XXX This API does not allow for cancellation. */ - if (!camel_service_connect_sync (service, &error)) { + if (!em_utils_connect_service_sync (service, cancellable, &error)) { g_simple_async_result_set_from_error (simple, error); g_error_free (error); return; @@ -441,7 +443,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple, context->recipients, cancellable, &error); if (did_connect) - camel_service_disconnect_sync (service, error == NULL, error ? NULL : &error); + em_utils_disconnect_service_sync (service, error == NULL, cancellable, error ? NULL : &error); if (error != NULL) { g_simple_async_result_set_from_error (simple, error); @@ -871,8 +873,8 @@ e_mail_session_unsubscribe_folder_sync (EMailSession *session, /* FIXME This should take our GCancellable. */ success = - camel_service_connect_sync ( - CAMEL_SERVICE (store), error) && + em_utils_connect_service_sync ( + CAMEL_SERVICE (store), cancellable, error) && camel_store_unsubscribe_folder_sync ( store, folder_name, cancellable, error); diff --git a/mail/e-mail-session.c b/mail/e-mail-session.c index 6b38d707da..1a3b9e8c0a 100644 --- a/mail/e-mail-session.c +++ b/mail/e-mail-session.c @@ -1045,7 +1045,7 @@ e_mail_session_get_inbox_sync (EMailSession *session, if (!CAMEL_IS_STORE (service)) return NULL; - if (!camel_service_connect_sync (service, error)) + if (!em_utils_connect_service_sync (service, cancellable, error)) return NULL; return camel_store_get_inbox_folder_sync ( @@ -1144,7 +1144,7 @@ e_mail_session_get_trash_sync (EMailSession *session, if (!CAMEL_IS_STORE (service)) return NULL; - if (!camel_service_connect_sync (service, error)) + if (!em_utils_connect_service_sync (service, cancellable, error)) return NULL; return camel_store_get_trash_folder_sync ( diff --git a/mail/e-mail-store-utils.c b/mail/e-mail-store-utils.c index c0d2466216..1b9713bee2 100644 --- a/mail/e-mail-store-utils.c +++ b/mail/e-mail-store-utils.c @@ -20,6 +20,8 @@ #include #endif +#include "em-utils.h" + #include "e-mail-store-utils.h" #include @@ -175,7 +177,7 @@ mail_store_go_offline_thread (GSimpleAsyncResult *simple, disco_store, CAMEL_DISCO_STORE_OFFLINE, cancellable, &error); else - camel_service_disconnect_sync (service, TRUE, &error); + em_utils_disconnect_service_sync (service, TRUE, cancellable, &error); } else if (CAMEL_IS_OFFLINE_STORE (store)) { CamelOfflineStore *offline_store; @@ -186,7 +188,7 @@ mail_store_go_offline_thread (GSimpleAsyncResult *simple, offline_store, FALSE, cancellable, &error); } else - camel_service_disconnect_sync (service, TRUE, &error); + em_utils_disconnect_service_sync (service, TRUE, cancellable, &error); if (error != NULL) { g_simple_async_result_set_from_error (simple, error); diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c index e5a3543fdc..4650405274 100644 --- a/mail/em-folder-utils.c +++ b/mail/em-folder-utils.c @@ -345,7 +345,7 @@ emfu_copy_folder_selected (EMailBackend *backend, session = e_mail_backend_get_session (backend); service = CAMEL_SERVICE (cfd->source_store); - camel_service_connect_sync (service, &local_error); + em_utils_connect_service_sync (service, NULL, &local_error); if (local_error != NULL) { e_mail_backend_submit_alert ( @@ -373,8 +373,8 @@ emfu_copy_folder_selected (EMailBackend *backend, tostore = NULL; if (tostore != NULL) - camel_service_connect_sync ( - CAMEL_SERVICE (tostore), &local_error); + em_utils_connect_service_sync ( + CAMEL_SERVICE (tostore), NULL, &local_error); if (local_error != NULL) { e_mail_backend_submit_alert ( diff --git a/mail/em-utils.c b/mail/em-utils.c index 3239b87214..a106a0ce04 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -2289,3 +2289,52 @@ em_utils_is_local_delivery_mbox_file (CamelURL *url) g_file_test (url->path, G_FILE_TEST_EXISTS) && !g_file_test (url->path, G_FILE_TEST_IS_DIR); } + +static void +cancel_service_connect_cb (GCancellable *cancellable, CamelService *service) +{ + g_return_if_fail (service != NULL); + g_return_if_fail (CAMEL_IS_SERVICE (service)); + + camel_service_cancel_connect (service); +} + +gboolean +em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error) +{ + gboolean res; + gulong handler_id = 0; + + g_return_val_if_fail (service != NULL, FALSE); + g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE); + + if (cancellable) + handler_id = g_cancellable_connect (cancellable, G_CALLBACK (cancel_service_connect_cb), service, NULL); + + res = camel_service_connect_sync (service, error); + + if (handler_id) + g_cancellable_disconnect (cancellable, handler_id); + + return res; +} + +gboolean +em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error) +{ + gboolean res; + gulong handler_id = 0; + + g_return_val_if_fail (service != NULL, FALSE); + g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE); + + if (cancellable) + handler_id = g_cancellable_connect (cancellable, G_CALLBACK (cancel_service_connect_cb), service, NULL); + + res = camel_service_disconnect_sync (service, clean, error); + + if (handler_id) + g_cancellable_disconnect (cancellable, handler_id); + + return res; +} diff --git a/mail/em-utils.h b/mail/em-utils.h index c516f15291..cb547e09a3 100644 --- a/mail/em-utils.h +++ b/mail/em-utils.h @@ -96,6 +96,9 @@ void emu_restore_folder_tree_state (EMFolderTree *folder_tree); gboolean em_utils_is_local_delivery_mbox_file (CamelURL *url); +gboolean em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error); +gboolean em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error); + G_END_DECLS #endif /* __EM_UTILS_H__ */ diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 0b3e27d24e..cf8453a953 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -339,7 +339,7 @@ fail: /* also disconnect if not a local delivery mbox; there is no need to keep the connection alive forever */ if (!is_local_delivery) - camel_service_disconnect_sync (CAMEL_SERVICE (m->store), TRUE, NULL); + em_utils_disconnect_service_sync (CAMEL_SERVICE (m->store), TRUE, cancellable, NULL); } static void @@ -580,8 +580,8 @@ mail_send_message (struct _send_queue_msg *m, } if (camel_address_length (recipients) > 0) { - if (!camel_service_connect_sync ( - CAMEL_SERVICE (transport), error)) + if (!em_utils_connect_service_sync ( + CAMEL_SERVICE (transport), cancellable, error)) goto exit; if (!camel_transport_send_to_sync ( @@ -1597,7 +1597,7 @@ disconnect_service_exec (struct _disconnect_msg *m, GCancellable *cancellable, GError **error) { - camel_service_disconnect_sync (CAMEL_SERVICE (m->store), TRUE, error); + em_utils_disconnect_service_sync (CAMEL_SERVICE (m->store), TRUE, cancellable, error); } static void diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index 4c46c4d84a..64b31f3497 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -1124,7 +1124,7 @@ vfolder_load_storage (EMailBackend *backend) CAMEL_SESSION (session), "vfolder", storeuri, CAMEL_PROVIDER_STORE, NULL); if (service != NULL) - camel_service_connect_sync (service, NULL); + em_utils_connect_service_sync (service, NULL, NULL); else { g_warning("Cannot open vfolder store - no vfolders available"); return; diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c index f342835375..47b10943db 100644 --- a/modules/mail/e-mail-shell-view.c +++ b/modules/mail/e-mail-shell-view.c @@ -553,7 +553,7 @@ all_accounts: /* FIXME Complete lack of error checking here. */ service = camel_session_get_service ( CAMEL_SESSION (session), "vfolder"); - camel_service_connect_sync (service, NULL); + em_utils_connect_service_sync (service, NULL, NULL); search_folder = (CamelVeeFolder *) camel_vee_folder_new ( CAMEL_STORE (service), _("All Account Search"), @@ -726,7 +726,7 @@ current_account: /* FIXME Complete lack of error checking here. */ service = camel_session_get_service ( CAMEL_SESSION (session), "vfolder"); - camel_service_connect_sync (service, NULL); + em_utils_connect_service_sync (service, NULL, NULL); search_folder = (CamelVeeFolder *) camel_vee_folder_new ( CAMEL_STORE (service), _("Account Search"), -- cgit v1.2.3