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

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