[evolution-data-server] Avoid local message cache expiry clean up when being offline



commit 409cff918e80483cf916c52f2d97fd3c4804db2b
Author: Milan Crha <mcrha redhat com>
Date:   Fri Feb 10 15:01:21 2017 +0100

    Avoid local message cache expiry clean up when being offline
    
    When an account (IMAPx and NNTP) is offline, then its locally stored
    messages should not be removed due to expiry, such thing should be
    done only in online, otherwise it could make message available
    in one second and then re-selecting it a second later it being
    unavailable, which is rather confusing and unexpected.

 src/camel/camel-data-cache.c                   |   83 +++++++++++++++++++++++-
 src/camel/camel-data-cache.h                   |    5 ++
 src/camel/providers/imapx/camel-imapx-folder.c |    4 +
 src/camel/providers/nntp/camel-nntp-store.c    |    4 +
 4 files changed, 94 insertions(+), 2 deletions(-)
---
diff --git a/src/camel/camel-data-cache.c b/src/camel/camel-data-cache.c
index cb3c75f..60b9ca1 100644
--- a/src/camel/camel-data-cache.c
+++ b/src/camel/camel-data-cache.c
@@ -54,6 +54,7 @@ struct _CamelDataCachePrivate {
 
        gchar *path;
 
+       gboolean expire_enabled;
        time_t expire_age;
        time_t expire_access;
 
@@ -62,7 +63,8 @@ struct _CamelDataCachePrivate {
 
 enum {
        PROP_0,
-       PROP_PATH
+       PROP_PATH,
+       PROP_EXPIRE_ENABLED
 };
 
 G_DEFINE_TYPE (CamelDataCache, camel_data_cache, G_TYPE_OBJECT)
@@ -79,6 +81,12 @@ data_cache_set_property (GObject *object,
                                CAMEL_DATA_CACHE (object),
                                g_value_get_string (value));
                        return;
+
+               case PROP_EXPIRE_ENABLED:
+                       camel_data_cache_set_expire_enabled (
+                               CAMEL_DATA_CACHE (object),
+                               g_value_get_boolean (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -96,6 +104,12 @@ data_cache_get_property (GObject *object,
                                value, camel_data_cache_get_path (
                                CAMEL_DATA_CACHE (object)));
                        return;
+
+               case PROP_EXPIRE_ENABLED:
+                       g_value_set_boolean (
+                               value, camel_data_cache_get_expire_enabled (
+                               CAMEL_DATA_CACHE (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -137,6 +151,17 @@ camel_data_cache_class_init (CamelDataCacheClass *class)
                        NULL,
                        G_PARAM_READWRITE |
                        G_PARAM_CONSTRUCT));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_EXPIRE_ENABLED,
+               g_param_spec_boolean (
+                       "expire-enabled",
+                       "Expire Enabled",
+                       NULL,
+                       TRUE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT));
 }
 
 static void
@@ -151,6 +176,7 @@ camel_data_cache_init (CamelDataCache *data_cache)
 
        data_cache->priv = CAMEL_DATA_CACHE_GET_PRIVATE (data_cache);
        data_cache->priv->busy_bag = busy_bag;
+       data_cache->priv->expire_enabled = TRUE;
        data_cache->priv->expire_age = -1;
        data_cache->priv->expire_access = -1;
 }
@@ -225,6 +251,59 @@ camel_data_cache_set_path (CamelDataCache *cdc,
 }
 
 /**
+ * camel_data_cache_get_expire_enabled:
+ * @cdc: a #CamelDataCache
+ *
+ * Gets whether expire of cache data is enabled.
+ *
+ * This is a complementary property for camel_data_cache_set_expire_age()
+ * and camel_data_cache_set_expire_access(), which allows to disable expiry
+ * without touching the two values. Having expire enabled, but not have set
+ * any of the two times, still behaves like not having expiry enabled.
+ *
+ * Returns: Whether expire is enabled.
+ *
+ * Since: 3.24
+ **/
+gboolean
+camel_data_cache_get_expire_enabled (CamelDataCache *cdc)
+{
+       g_return_val_if_fail (CAMEL_IS_DATA_CACHE (cdc), FALSE);
+
+       return cdc->priv->expire_enabled;
+}
+
+/**
+ * camel_data_cache_set_expire_enabled:
+ * @cdc: a #CamelDataCache
+ * @expire_enabled: a value to set
+ *
+ * Sets whether expire of cache data is enabled.
+ *
+ * This is a complementary property for camel_data_cache_set_expire_age()
+ * and camel_data_cache_set_expire_access(), which allows to disable expiry
+ * without touching the two values. Having expire enabled, but not have set
+ * any of the two times, still behaves like not having expiry enabled.
+ *
+ * Returns: Whether expire is enabled.
+ *
+ * Since: 3.24
+ **/
+void
+camel_data_cache_set_expire_enabled (CamelDataCache *cdc,
+                                    gboolean expire_enabled)
+{
+       g_return_if_fail (CAMEL_IS_DATA_CACHE (cdc));
+
+       if (!cdc->priv->expire_enabled == !expire_enabled)
+               return;
+
+       cdc->priv->expire_enabled = expire_enabled;
+
+       g_object_notify (G_OBJECT (cdc), "expire-enabled");
+}
+
+/**
  * camel_data_cache_set_expire_age:
  * @cdc: A #CamelDataCache
  * @when: Timeout for age expiry, or -1 to disable.
@@ -337,7 +416,7 @@ data_cache_path (CamelDataCache *cdc,
        if (g_access (dir, F_OK) == -1) {
                if (create)
                        g_mkdir_with_parents (dir, 0700);
-       } else if (cdc->priv->expire_age != -1 || cdc->priv->expire_access != -1) {
+       } else if (cdc->priv->expire_enabled && (cdc->priv->expire_age != -1 || cdc->priv->expire_access != 
-1)) {
                time_t now;
 
                /* This has a race, but at worst we re-run an expire cycle which is safe */
diff --git a/src/camel/camel-data-cache.h b/src/camel/camel-data-cache.h
index 3d616ee..e5725f2 100644
--- a/src/camel/camel-data-cache.h
+++ b/src/camel/camel-data-cache.h
@@ -70,6 +70,11 @@ CamelDataCache *camel_data_cache_new         (const gchar *path,
 const gchar *  camel_data_cache_get_path       (CamelDataCache *cdc);
 void           camel_data_cache_set_path       (CamelDataCache *cdc,
                                                 const gchar *path);
+gboolean       camel_data_cache_get_expire_enabled
+                                               (CamelDataCache *cdc);
+void           camel_data_cache_set_expire_enabled
+                                               (CamelDataCache *cdc,
+                                                gboolean expire_enabled);
 void           camel_data_cache_set_expire_age (CamelDataCache *cdc,
                                                 time_t when);
 void           camel_data_cache_set_expire_access
diff --git a/src/camel/providers/imapx/camel-imapx-folder.c b/src/camel/providers/imapx/camel-imapx-folder.c
index 4b395d6..120e63f 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -1141,6 +1141,10 @@ camel_imapx_folder_new (CamelStore *store,
                camel_data_cache_set_expire_access (imapx_folder->cache, 60 * 60 * 24 * 7);
        }
 
+       camel_binding_bind_property (store, "online",
+               imapx_folder->cache, "expire-enabled",
+               G_BINDING_SYNC_CREATE);
+
        imapx_folder->search = camel_imapx_search_new (CAMEL_IMAPX_STORE (store));
 
        if (filter_all)
diff --git a/src/camel/providers/nntp/camel-nntp-store.c b/src/camel/providers/nntp/camel-nntp-store.c
index bce0595..b2e1677 100644
--- a/src/camel/providers/nntp/camel-nntp-store.c
+++ b/src/camel/providers/nntp/camel-nntp-store.c
@@ -1508,6 +1508,10 @@ nntp_store_initable_init (GInitable *initable,
        camel_data_cache_set_expire_age (nntp_cache, 60 * 60 * 24 * 14);
        camel_data_cache_set_expire_access (nntp_cache, 60 * 60 * 24 * 5);
 
+       camel_binding_bind_property (nntp_store, "online",
+               nntp_cache, "expire-enabled",
+               G_BINDING_SYNC_CREATE);
+
        nntp_store->priv->cache = nntp_cache;  /* takes ownership */
 
        return TRUE;


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