[evolution-ews] eds-I#208 - Avoid race condition when refreshing collection backend
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] eds-I#208 - Avoid race condition when refreshing collection backend
- Date: Fri, 28 Aug 2020 12:23:42 +0000 (UTC)
commit d01a32bc21ccf370f3438774a7b3e5841f2af043
Author: Milan Crha <mcrha redhat com>
Date: Fri Aug 28 14:23:13 2020 +0200
eds-I#208 - Avoid race condition when refreshing collection backend
Related to https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/208
src/EWS/registry/e-ews-backend.c | 17 +++++++++++++++++
src/Microsoft365/registry/e-m365-backend.c | 17 +++++++++++++++++
2 files changed, 34 insertions(+)
---
diff --git a/src/EWS/registry/e-ews-backend.c b/src/EWS/registry/e-ews-backend.c
index eaa82ba3..c01e3172 100644
--- a/src/EWS/registry/e-ews-backend.c
+++ b/src/EWS/registry/e-ews-backend.c
@@ -751,6 +751,8 @@ ews_backend_folders_synced_cb (GObject *source,
if (!e_ews_backend_sync_folders_finish (ews_backend, result, NULL))
ews_backend_claim_old_resources (E_COLLECTION_BACKEND (ews_backend));
+
+ e_collection_backend_thaw_populate (E_COLLECTION_BACKEND (ews_backend));
}
static void
@@ -773,6 +775,11 @@ ews_backend_populate (ECollectionBackend *backend)
if (!e_source_get_enabled (source))
return;
+ if (!e_collection_backend_freeze_populate (backend)) {
+ e_collection_backend_thaw_populate (backend);
+ return;
+ }
+
ews_backend_add_gal_source (ews_backend);
ews_backend_claim_old_resources (backend);
@@ -789,6 +796,8 @@ ews_backend_populate (ECollectionBackend *backend)
NULL, NULL);
}
}
+
+ e_collection_backend_thaw_populate (backend);
}
static gchar *
@@ -1115,6 +1124,7 @@ ews_backend_authenticate_sync (EBackend *backend,
EEwsConnection *connection;
CamelEwsSettings *ews_settings;
ESourceAuthenticationResult result = E_SOURCE_AUTHENTICATION_ERROR;
+ gboolean in_sync_folders = FALSE;
g_return_val_if_fail (E_IS_EWS_BACKEND (backend), E_SOURCE_AUTHENTICATION_ERROR);
@@ -1122,6 +1132,8 @@ ews_backend_authenticate_sync (EBackend *backend,
ews_settings = ews_backend_get_settings (ews_backend);
g_return_val_if_fail (ews_settings != NULL, E_SOURCE_AUTHENTICATION_ERROR);
+ e_collection_backend_freeze_populate (E_COLLECTION_BACKEND (backend));
+
g_mutex_lock (&ews_backend->priv->connection_lock);
g_clear_object (&ews_backend->priv->connection);
e_named_parameters_free (ews_backend->priv->credentials);
@@ -1135,6 +1147,8 @@ ews_backend_authenticate_sync (EBackend *backend,
e_collection_backend_authenticate_children (E_COLLECTION_BACKEND (backend), credentials);
e_ews_backend_sync_folders (ews_backend, NULL, ews_backend_folders_synced_cb, NULL);
+
+ in_sync_folders = TRUE;
} else if (e_ews_connection_utils_get_without_password (ews_settings) &&
result == E_SOURCE_AUTHENTICATION_REJECTED &&
!e_named_parameters_exists (credentials, E_SOURCE_CREDENTIAL_PASSWORD)) {
@@ -1142,6 +1156,9 @@ ews_backend_authenticate_sync (EBackend *backend,
result = E_SOURCE_AUTHENTICATION_REQUIRED;
}
+ if (!in_sync_folders)
+ e_collection_backend_thaw_populate (E_COLLECTION_BACKEND (backend));
+
return result;
}
diff --git a/src/Microsoft365/registry/e-m365-backend.c b/src/Microsoft365/registry/e-m365-backend.c
index e60f68fa..1eef5f81 100644
--- a/src/Microsoft365/registry/e-m365-backend.c
+++ b/src/Microsoft365/registry/e-m365-backend.c
@@ -89,10 +89,17 @@ m365_backend_populate (ECollectionBackend *backend)
if (!e_source_get_enabled (source))
return;
+ if (!e_collection_backend_freeze_populate (backend)) {
+ e_collection_backend_thaw_populate (backend);
+ return;
+ }
+
m365_backend_claim_old_resources (backend);
if (e_backend_get_online (E_BACKEND (backend)))
e_backend_schedule_authenticate (E_BACKEND (backend), NULL);
+
+ e_collection_backend_thaw_populate (backend);
}
static void
@@ -516,6 +523,8 @@ m365_backend_sync_folders_thread (GTask *task,
m365_backend_sync_task_folders_sync (m365_backend, cnc, cancellable);
#endif
}
+
+ e_collection_backend_thaw_populate (E_COLLECTION_BACKEND (m365_backend));
}
static void
@@ -826,9 +835,12 @@ m365_backend_authenticate_sync (EBackend *backend,
CamelM365Settings *m365_settings;
EM365Connection *cnc;
ESourceAuthenticationResult result;
+ gboolean in_sync_folders = FALSE;
g_return_val_if_fail (E_IS_M365_BACKEND (backend), E_SOURCE_AUTHENTICATION_ERROR);
+ e_collection_backend_freeze_populate (E_COLLECTION_BACKEND (backend));
+
m365_settings = camel_m365_settings_get_from_backend (backend, NULL);
g_return_val_if_fail (m365_settings != NULL, E_SOURCE_AUTHENTICATION_ERROR);
@@ -839,6 +851,8 @@ m365_backend_authenticate_sync (EBackend *backend,
if (result == E_SOURCE_AUTHENTICATION_ACCEPTED) {
e_collection_backend_authenticate_children (E_COLLECTION_BACKEND (backend), credentials);
m365_backend_sync_folders (E_M365_BACKEND (backend), cnc, NULL, NULL, NULL);
+
+ in_sync_folders = TRUE;
} else if (result == E_SOURCE_AUTHENTICATION_REJECTED &&
!e_named_parameters_exists (credentials, E_SOURCE_CREDENTIAL_PASSWORD)) {
result = E_SOURCE_AUTHENTICATION_REQUIRED;
@@ -846,6 +860,9 @@ m365_backend_authenticate_sync (EBackend *backend,
g_clear_object (&cnc);
+ if (!in_sync_folders)
+ e_collection_backend_thaw_populate (E_COLLECTION_BACKEND (backend));
+
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]