[gnome-software: 13/14] gs-plugin-loader: Don’t modify plugin locations during setup




commit 1ebd7bf8ebcd77e0826142521fbae3985ab50a4a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 1 16:16:46 2022 +0000

    gs-plugin-loader: Don’t modify plugin locations during setup
    
    Otherwise calling `gs_plugin_loader_add_location()` before the next call
    to `setup_async()` will give unexpected results.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1661

 lib/gs-plugin-loader.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index e361e4fa3..2448bbdf5 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2323,6 +2323,7 @@ gs_plugin_loader_setup_async (GsPluginLoader      *plugin_loader,
        g_autoptr(SetupData) setup_data_owned = NULL;
        g_autoptr(GsPluginLoaderHelper) helper = NULL;
        g_autoptr(GsPluginJob) plugin_job = NULL;
+       g_autoptr(GPtrArray) locations = NULL;
        g_autoptr(GTask) task = NULL;
        g_autoptr(GError) local_error = NULL;
 #ifdef HAVE_SYSPROF
@@ -2336,12 +2337,15 @@ gs_plugin_loader_setup_async (GsPluginLoader      *plugin_loader,
        if (plugin_loader->locations->len == 0) {
                g_autofree gchar *filename = NULL;
                filename = g_strdup_printf ("plugins-%s", GS_PLUGIN_API_VERSION);
-               g_ptr_array_add (plugin_loader->locations, g_build_filename (LIBDIR, "gnome-software", 
filename, NULL));
+               locations = g_ptr_array_new_with_free_func (g_free);
+               g_ptr_array_add (locations, g_build_filename (LIBDIR, "gnome-software", filename, NULL));
+       } else {
+               locations = g_ptr_array_ref (plugin_loader->locations);
        }
 
-       for (i = 0; i < plugin_loader->locations->len; i++) {
+       for (i = 0; i < locations->len; i++) {
                GFileMonitor *monitor;
-               const gchar *location = g_ptr_array_index (plugin_loader->locations, i);
+               const gchar *location = g_ptr_array_index (locations, i);
                g_autoptr(GFile) plugin_dir = g_file_new_for_path (location);
                g_debug ("monitoring plugin location %s", location);
                monitor = g_file_monitor_directory (plugin_dir,
@@ -2359,8 +2363,8 @@ gs_plugin_loader_setup_async (GsPluginLoader      *plugin_loader,
        }
 
        /* search for plugins */
-       for (i = 0; i < plugin_loader->locations->len; i++) {
-               const gchar *location = g_ptr_array_index (plugin_loader->locations, i);
+       for (i = 0; i < locations->len; i++) {
+               const gchar *location = g_ptr_array_index (locations, i);
                g_autoptr(GPtrArray) fns = NULL;
 
                /* search in the plugin directory for plugins */


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