[evolution-data-server] I#68 - WebDAV registry backend Refresh can remove existing sources ][



commit 91fc380495b5316a1a9f0adfb2476398278685aa
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 26 08:39:48 2019 +0100

    I#68 - WebDAV registry backend Refresh can remove existing sources ][
    
    This covers cases where the client fails to connect to the server, or when
    there's a server error, to not remove existing sources, but rather keep them
    until the next successful refresh.
    
    Related to https://gitlab.gnome.org/GNOME/evolution-data-server/issues/68

 src/libebackend/e-webdav-collection-backend.c | 48 +++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
---
diff --git a/src/libebackend/e-webdav-collection-backend.c b/src/libebackend/e-webdav-collection-backend.c
index 76835cb38..26b30b2d4 100644
--- a/src/libebackend/e-webdav-collection-backend.c
+++ b/src/libebackend/e-webdav-collection-backend.c
@@ -430,6 +430,38 @@ e_webdav_collection_backend_is_custom_source (EWebDAVCollectionBackend *webdav_b
        return klass->is_custom_source (webdav_backend, source);
 }
 
+typedef struct _RemoveSourceTypesData {
+       ESourceRegistryServer *server;
+       gboolean calendars;
+} RemoveSourceTypesData;
+
+static gboolean
+webdav_collection_remove_source_types_cb (gpointer key,
+                                         gpointer value,
+                                         gpointer user_data)
+{
+       RemoveSourceTypesData *rstd = user_data;
+       const gchar *source_uid = value;
+       ESource *source;
+       gboolean remove;
+
+       g_return_val_if_fail (rstd != NULL, FALSE);
+
+       source = e_source_registry_server_ref_source (rstd->server, source_uid);
+       if (!source)
+               return FALSE;
+
+       remove = (rstd->calendars && (
+                 e_source_has_extension (source, E_SOURCE_EXTENSION_CALENDAR) ||
+                 e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST) ||
+                 e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST))) ||
+                (!rstd->calendars && e_source_has_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK));
+
+       g_object_unref (source);
+
+       return remove;
+}
+
 /**
  * e_webdav_collection_backend_discover_sync:
  * @webdav_backend: an #EWebDAVCollectionBackend
@@ -523,6 +555,14 @@ e_webdav_collection_backend_discover_sync (EWebDAVCollectionBackend *webdav_back
                e_webdav_discover_free_discovered_sources (discovered_sources);
                discovered_sources = NULL;
                any_success = TRUE;
+       } else if (local_error && local_error->domain == SOUP_HTTP_ERROR && (
+                  SOUP_STATUS_IS_TRANSPORT_ERROR (local_error->code) || SOUP_STATUS_IS_SERVER_ERROR 
(local_error->code))) {
+               RemoveSourceTypesData rstd;
+
+               rstd.server = server;
+               rstd.calendars = TRUE;
+
+               g_hash_table_foreach_remove (known_sources, webdav_collection_remove_source_types_cb, &rstd);
        }
 
        if (!local_error && e_source_collection_get_contacts_enabled (collection_extension) && contacts_url &&
@@ -539,6 +579,14 @@ e_webdav_collection_backend_discover_sync (EWebDAVCollectionBackend *webdav_back
                e_webdav_discover_free_discovered_sources (discovered_sources);
                discovered_sources = NULL;
                any_success = TRUE;
+       } else if (any_success && local_error && local_error->domain == SOUP_HTTP_ERROR && (
+                  SOUP_STATUS_IS_TRANSPORT_ERROR (local_error->code) || SOUP_STATUS_IS_SERVER_ERROR 
(local_error->code))) {
+               RemoveSourceTypesData rstd;
+
+               rstd.server = server;
+               rstd.calendars = FALSE;
+
+               g_hash_table_foreach_remove (known_sources, webdav_collection_remove_source_types_cb, &rstd);
        }
 
        if (any_success && server && !g_cancellable_is_cancelled (cancellable)) {


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