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

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