Blame SOURCES/evolution-data-server-3.28.5-delay-new-module-load.patch

f0a9c3
diff -up evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c.delay-new-module-load evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c
f0a9c3
--- evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c.delay-new-module-load	2018-07-30 15:17:06.000000000 +0200
f0a9c3
+++ evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c	2020-01-15 13:29:46.090644022 +0100
f0a9c3
@@ -75,6 +75,78 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
f0a9c3
 	EDBusServer, e_dbus_server, G_TYPE_OBJECT,
f0a9c3
 	G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
f0a9c3
 
f0a9c3
+typedef struct _ModuleLoadData {
f0a9c3
+	GWeakRef server_wr;
f0a9c3
+	gchar *filename;
f0a9c3
+} ModuleLoadData;
f0a9c3
+
f0a9c3
+static ModuleLoadData *
f0a9c3
+module_load_data_new (EDBusServer *server,
f0a9c3
+		      const gchar *filename)
f0a9c3
+{
f0a9c3
+	ModuleLoadData *mld;
f0a9c3
+
f0a9c3
+	mld = g_slice_new0 (ModuleLoadData);
f0a9c3
+	g_weak_ref_init (&mld->server_wr, server);
f0a9c3
+	mld->filename = g_strdup (filename);
f0a9c3
+
f0a9c3
+	return mld;
f0a9c3
+}
f0a9c3
+
f0a9c3
+static void
f0a9c3
+module_load_data_free (gpointer ptr)
f0a9c3
+{
f0a9c3
+	ModuleLoadData *mld = ptr;
f0a9c3
+
f0a9c3
+	if (mld) {
f0a9c3
+		g_weak_ref_clear (&mld->server_wr);
f0a9c3
+		g_free (mld->filename);
f0a9c3
+		g_slice_free (ModuleLoadData, mld);
f0a9c3
+	}
f0a9c3
+}
f0a9c3
+
f0a9c3
+static gboolean
f0a9c3
+e_dbus_server_load_module_timeout_cb (gpointer user_data)
f0a9c3
+{
f0a9c3
+	ModuleLoadData *mld = user_data;
f0a9c3
+	EDBusServer *server;
f0a9c3
+
f0a9c3
+	g_return_val_if_fail (mld != NULL, FALSE);
f0a9c3
+
f0a9c3
+	server = g_weak_ref_get (&mld->server_wr);
f0a9c3
+	if (server) {
f0a9c3
+		EModule *module;
f0a9c3
+
f0a9c3
+		e_source_registry_debug_print ("Loading module '%s'\n", mld->filename);
f0a9c3
+
f0a9c3
+		module = e_module_load_file (mld->filename);
f0a9c3
+		if (module) {
f0a9c3
+			g_type_module_unuse ((GTypeModule *) module);
f0a9c3
+
f0a9c3
+			e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD);
f0a9c3
+		}
f0a9c3
+
f0a9c3
+		g_object_unref (server);
f0a9c3
+	}
f0a9c3
+
f0a9c3
+	return FALSE;
f0a9c3
+}
f0a9c3
+
f0a9c3
+static void
f0a9c3
+e_dbus_server_schedule_module_load (EDBusServer *server,
f0a9c3
+				    const gchar *filename)
f0a9c3
+{
f0a9c3
+	g_return_if_fail (E_IS_DBUS_SERVER (server));
f0a9c3
+	g_return_if_fail (filename != NULL);
f0a9c3
+
f0a9c3
+	e_source_registry_debug_print ("Schedule load of module '%s'\n", filename);
f0a9c3
+
f0a9c3
+	/* Delay the load by 10 seconds, in case the module doesn't have placed
f0a9c3
+	   all its libraries in the expected directories. */
f0a9c3
+	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 10, e_dbus_server_load_module_timeout_cb,
f0a9c3
+		module_load_data_new (server, filename), module_load_data_free);
f0a9c3
+}
f0a9c3
+
f0a9c3
 static void
f0a9c3
 dbus_server_bus_acquired_cb (GDBusConnection *connection,
f0a9c3
                              const gchar *bus_name,
f0a9c3
@@ -552,38 +624,27 @@ dbus_server_module_directory_changed_cb
f0a9c3
 		if (event_type == G_FILE_MONITOR_EVENT_RENAMED && other_file) {
f0a9c3
 			G_LOCK (loaded_modules);
f0a9c3
 			if (!g_hash_table_contains (loaded_modules, filename)) {
f0a9c3
+				gchar *other_filename = g_file_get_path (other_file);
f0a9c3
+				e_source_registry_debug_print ("Module file '%s' renamed to '%s'\n", filename, other_filename);
f0a9c3
 				g_free (filename);
f0a9c3
-				filename = g_file_get_path (other_file);
f0a9c3
+				filename = other_filename;
f0a9c3
 				event_type = G_FILE_MONITOR_EVENT_CREATED;
f0a9c3
 			}
f0a9c3
 			G_UNLOCK (loaded_modules);
f0a9c3
 		}
f0a9c3
 
f0a9c3
 		if (filename && g_str_has_suffix (filename, "." G_MODULE_SUFFIX)) {
f0a9c3
-			gboolean any_loaded = FALSE;
f0a9c3
-
f0a9c3
 			if (event_type == G_FILE_MONITOR_EVENT_CREATED ||
f0a9c3
 			    event_type == G_FILE_MONITOR_EVENT_MOVED_IN) {
f0a9c3
 				G_LOCK (loaded_modules);
f0a9c3
 
f0a9c3
 				if (!g_hash_table_contains (loaded_modules, filename)) {
f0a9c3
-					EModule *module;
f0a9c3
-
f0a9c3
 					g_hash_table_add (loaded_modules, g_strdup (filename));
f0a9c3
-
f0a9c3
-					module = e_module_load_file (filename);
f0a9c3
-					if (module) {
f0a9c3
-						any_loaded = TRUE;
f0a9c3
-
f0a9c3
-						g_type_module_unuse ((GTypeModule *) module);
f0a9c3
-					}
f0a9c3
+					e_dbus_server_schedule_module_load (server, filename);
f0a9c3
 				}
f0a9c3
 
f0a9c3
 				G_UNLOCK (loaded_modules);
f0a9c3
 			}
f0a9c3
-
f0a9c3
-			if (any_loaded)
f0a9c3
-				e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD);
f0a9c3
 		}
f0a9c3
 
f0a9c3
 		g_free (filename);