[evolution-data-server] Bug 761527 - Local calendar interval tree not always updated



commit 632181e06c8cad952c30a218c42d404c0531f363
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 10 19:44:01 2016 +0100

    Bug 761527 - Local calendar interval tree not always updated

 calendar/backends/file/e-cal-backend-file.c |   41 ++++++++++++++++++++++----
 1 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 0b7a99e..b8e0e43 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -298,6 +298,8 @@ free_calendar_data (ECalBackendFile *cbfile)
 
        priv = cbfile->priv;
 
+       g_rec_mutex_lock (&priv->idle_save_rmutex);
+
        e_intervaltree_destroy (priv->interval_tree);
        priv->interval_tree = NULL;
 
@@ -307,6 +309,8 @@ free_calendar_data (ECalBackendFile *cbfile)
 
        g_list_free (priv->comp);
        priv->comp = NULL;
+
+       g_rec_mutex_unlock (&priv->idle_save_rmutex);
 }
 
 /* Dispose handler for the file backend */
@@ -629,15 +633,15 @@ get_rid_icaltime (ECalComponent *comp)
 
 /* Adds component to the interval tree
  */
-static gboolean
+static void
 add_component_to_intervaltree (ECalBackendFile *cbfile,
                                ECalComponent *comp)
 {
        time_t time_start = -1, time_end = -1;
        ECalBackendFilePrivate *priv;
 
-       g_return_val_if_fail (cbfile != NULL, FALSE);
-       g_return_val_if_fail (comp != NULL, FALSE);
+       g_return_if_fail (cbfile != NULL);
+       g_return_if_fail (comp != NULL);
 
        priv = cbfile->priv;
 
@@ -650,10 +654,11 @@ add_component_to_intervaltree (ECalBackendFile *cbfile,
                gchar *str = e_cal_component_get_as_string (comp);
                g_print ("Bogus component %s\n", str);
                g_free (str);
-       } else
+       } else {
+               g_rec_mutex_lock (&priv->idle_save_rmutex);
                e_intervaltree_insert (priv->interval_tree, time_start, time_end, comp);
-
-       return FALSE;
+               g_rec_mutex_unlock (&priv->idle_save_rmutex);
+       }
 }
 
 static gboolean
@@ -672,7 +677,11 @@ remove_component_from_intervaltree (ECalBackendFile *cbfile,
 
        rid = e_cal_component_get_recurid_as_string (comp);
        e_cal_component_get_uid (comp, &uid);
+
+       g_rec_mutex_lock (&priv->idle_save_rmutex);
        res = e_intervaltree_remove (priv->interval_tree, uid, rid);
+       g_rec_mutex_unlock (&priv->idle_save_rmutex);
+
        g_free (rid);
 
        return res;
@@ -776,7 +785,7 @@ remove_recurrence_cb (gpointer key,
 
        if (!remove_component_from_intervaltree (cbfile, comp)) {
                g_message (G_STRLOC " Could not remove component from interval tree!");
-               }
+       }
        icalcomponent_remove_component (priv->icalcomp, icalcomp);
 
        /* remove it from our mapping */
@@ -1127,6 +1136,8 @@ open_cal (ECalBackendFile *cbfile,
                return;
        }
 
+       g_rec_mutex_lock (&priv->idle_save_rmutex);
+
        cal_backend_file_take_icalcomp (cbfile, icalcomp);
        priv->path = uri_to_path (E_CAL_BACKEND (cbfile));
 
@@ -1134,6 +1145,8 @@ open_cal (ECalBackendFile *cbfile,
        priv->interval_tree = e_intervaltree_new ();
        scan_vcalendar (cbfile);
 
+       g_rec_mutex_unlock (&priv->idle_save_rmutex);
+
        prepare_refresh_data (cbfile);
 }
 
@@ -1254,6 +1267,8 @@ reload_cal (ECalBackendFile *cbfile,
 
        /* Keep old data for comparison - free later */
 
+       g_rec_mutex_lock (&priv->idle_save_rmutex);
+
        icalcomp_old = priv->icalcomp;
        priv->icalcomp = NULL;
 
@@ -1272,6 +1287,8 @@ reload_cal (ECalBackendFile *cbfile,
 
        priv->path = uri_to_path (E_CAL_BACKEND (cbfile));
 
+       g_rec_mutex_unlock (&priv->idle_save_rmutex);
+
        /* Compare old and new versions of calendar */
 
        notify_changes (cbfile, comp_uid_hash_old, priv->comp_uid_hash);
@@ -1304,6 +1321,8 @@ create_cal (ECalBackendFile *cbfile,
 
        g_free (dirname);
 
+       g_rec_mutex_lock (&priv->idle_save_rmutex);
+
        /* Create the new calendar information */
        icalcomp = e_cal_util_new_top_level ();
        cal_backend_file_take_icalcomp (cbfile, icalcomp);
@@ -1314,6 +1333,8 @@ create_cal (ECalBackendFile *cbfile,
 
        priv->path = uri_to_path (E_CAL_BACKEND (cbfile));
 
+       g_rec_mutex_unlock (&priv->idle_save_rmutex);
+
        save (cbfile, TRUE);
 
        prepare_refresh_data (cbfile);
@@ -2463,6 +2484,12 @@ e_cal_backend_file_modify_objects (ECalBackendSync *backend,
 
                                e_cal_recur_ensure_end_dates (comp, TRUE, resolve_tzid, priv->icalcomp);
 
+                               if (!remove_component_from_intervaltree (cbfile, comp)) {
+                                       g_message (G_STRLOC " Could not remove component from interval 
tree!");
+                               }
+
+                               add_component_to_intervaltree (cbfile, comp);
+
                                icalcomponent_add_component (
                                        priv->icalcomp,
                                        e_cal_component_get_icalcomponent (obj_data->full_object));


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