[evolution-data-server] Bug 731562 - [IMAPx] Occasionally getting 'Empty cache file' error



commit a24277eaf1ade37c5386dca913104c63af676e87
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 16 14:55:51 2014 +0200

    Bug 731562 - [IMAPx] Occasionally getting 'Empty cache file' error

 camel/providers/imapx/camel-imapx-command.c |    8 ++++++-
 camel/providers/imapx/camel-imapx-job.c     |   30 +++++++++++++++++++++++++++
 camel/providers/imapx/camel-imapx-job.h     |    3 ++
 camel/providers/imapx/camel-imapx-server.c  |   25 +++++++++++++++++++++-
 4 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-command.c b/camel/providers/imapx/camel-imapx-command.c
index 4442355..09e88ec 100644
--- a/camel/providers/imapx/camel-imapx-command.c
+++ b/camel/providers/imapx/camel-imapx-command.c
@@ -596,7 +596,10 @@ camel_imapx_command_failed (CamelIMAPXCommand *ic,
        g_return_if_fail (error != NULL);
 
        real_ic = (CamelIMAPXRealCommand *) ic;
-       g_return_if_fail (real_ic->error == NULL);
+
+       /* Do not overwrite errors, the first passed in wins */
+       if (real_ic->error != NULL)
+               return;
 
        real_ic->error = g_error_copy (error);
 }
@@ -643,6 +646,9 @@ camel_imapx_command_set_error_if_failed (CamelIMAPXCommand *ic,
                return TRUE;
        }
 
+       if (real_ic->job)
+               return camel_imapx_job_set_error_if_failed (real_ic->job, error);
+
        return FALSE;
 }
 
diff --git a/camel/providers/imapx/camel-imapx-job.c b/camel/providers/imapx/camel-imapx-job.c
index dc6e473..fe3d7cf 100644
--- a/camel/providers/imapx/camel-imapx-job.c
+++ b/camel/providers/imapx/camel-imapx-job.c
@@ -417,3 +417,33 @@ camel_imapx_job_take_error (CamelIMAPXJob *job,
        real_job->error = error;  /* takes ownership */
 }
 
+/**
+ * camel_imapx_job_set_error_if_failed:
+ * @job: a #CamelIMAPXJob
+ * @error: a location for a #GError
+ *
+ * Sets @error to a new GError instance and returns TRUE, if the job has set
+ * an error or when it was cancelled.
+ *
+ * Returns: Whether the job failed.
+ *
+ * Since: 3.14
+ **/
+gboolean
+camel_imapx_job_set_error_if_failed (CamelIMAPXJob *job,
+                                    GError **error)
+{
+       CamelIMAPXRealJob *real_job;
+
+       g_return_if_fail (CAMEL_IS_IMAPX_JOB (job));
+       g_return_if_fail (error != NULL);
+
+       real_job = (CamelIMAPXRealJob *) job;
+
+       if (real_job->error) {
+               g_propagate_error (error, g_error_copy (real_job->error));
+               return TRUE;
+       }
+
+       return g_cancellable_set_error_if_cancelled (real_job->cancellable, error);
+}
diff --git a/camel/providers/imapx/camel-imapx-job.h b/camel/providers/imapx/camel-imapx-job.h
index ec214c0..b234880 100644
--- a/camel/providers/imapx/camel-imapx-job.h
+++ b/camel/providers/imapx/camel-imapx-job.h
@@ -80,6 +80,9 @@ void          camel_imapx_job_set_mailbox     (CamelIMAPXJob *job,
 GCancellable * camel_imapx_job_get_cancellable (CamelIMAPXJob *job);
 void           camel_imapx_job_take_error      (CamelIMAPXJob *job,
                                                 GError *error);
+gboolean       camel_imapx_job_set_error_if_failed
+                                               (CamelIMAPXJob *job,
+                                                GError **error);
 
 G_END_DECLS
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index b2522f2..e024fb3 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1384,7 +1384,9 @@ imapx_command_start_next (CamelIMAPXServer *is)
                return;
        }
 
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_pending);
+       g_mutex_unlock (&is->priv->select_lock);
        if (mailbox != NULL) {
                CamelIMAPXCommand *start_ic = NULL;
                GList *head, *link;
@@ -1489,7 +1491,9 @@ imapx_command_start_next (CamelIMAPXServer *is)
        }
 
        /* See if any queued jobs on this select first */
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+       g_mutex_unlock (&is->priv->select_lock);
        if (mailbox != NULL) {
                CamelIMAPXCommand *start_ic = NULL;
                GList *head, *link;
@@ -1612,7 +1616,9 @@ imapx_command_start_next (CamelIMAPXServer *is)
 
                min_pri = first_ic->pri;
 
+               g_mutex_lock (&is->priv->select_lock);
                mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+               g_mutex_unlock (&is->priv->select_lock);
 
                head = camel_imapx_command_queue_peek_head_link (is->queue);
 
@@ -1750,7 +1756,10 @@ imapx_match_active_job (CamelIMAPXServer *is,
                if (!(job->type & type))
                        continue;
 
+               g_mutex_lock (&is->priv->select_lock);
                mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+               g_mutex_unlock (&is->priv->select_lock);
+
                job_matches = camel_imapx_job_matches (job, mailbox, uid);
                g_clear_object (&mailbox);
 
@@ -1805,7 +1814,10 @@ imapx_expunge_uid_from_summary (CamelIMAPXServer *is,
        CamelMessageInfo *mi;
        guint32 messages;
 
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+       g_mutex_unlock (&is->priv->select_lock);
+
        g_return_if_fail (mailbox != NULL);
 
        folder = imapx_server_ref_folder (is, mailbox);
@@ -1888,7 +1900,9 @@ imapx_untagged_expunge (CamelIMAPXServer *is,
 
        c (is->tagprefix, "expunged: %lu\n", is->priv->context->id);
 
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+       g_mutex_unlock (&is->priv->select_lock);
 
        if (mailbox != NULL) {
                CamelFolder *folder;
@@ -1954,7 +1968,10 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
        if (uids == NULL)
                return FALSE;
 
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+       g_mutex_unlock (&is->priv->select_lock);
+
        g_return_val_if_fail (mailbox != NULL, FALSE);
 
        folder = imapx_server_ref_folder (is, mailbox);
@@ -1988,7 +2005,7 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
 
                uid = g_array_index (uids, guint32, ii);
 
-               c (is->tagprefix, "vanished: %u\n", uid);
+               e (is->tagprefix, "vanished: %u\n", uid);
 
                str = g_strdup_printf ("%u", uid);
                uid_list = g_list_prepend (uid_list, str);
@@ -3255,7 +3272,10 @@ imapx_completion (CamelIMAPXServer *is,
                CamelFolder *folder;
                CamelIMAPXMailbox *mailbox;
 
+               g_mutex_lock (&is->priv->select_lock);
                mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+               g_mutex_unlock (&is->priv->select_lock);
+
                g_return_val_if_fail (mailbox != NULL, FALSE);
 
                folder = imapx_server_ref_folder (is, mailbox);
@@ -3664,7 +3684,10 @@ imapx_call_idle (gpointer data)
        if (is->priv->idle_state != IMAPX_IDLE_PENDING)
                goto exit;
 
+       g_mutex_lock (&is->priv->select_lock);
        mailbox = g_weak_ref_get (&is->priv->select_mailbox);
+       g_mutex_unlock (&is->priv->select_lock);
+
        if (mailbox == NULL)
                goto exit;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]