[gnome-software: 2/14] gs-plugin-loader: Call setup() from setup_again()




commit a47128c5c91f78ffa27e78ac360ec430eda6254f
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 1 13:00:26 2022 +0000

    gs-plugin-loader: Call setup() from setup_again()
    
    Rather than calling `call_setup()`. This means that the work to load the
    plugins is re-done, but that shouldn’t be a problem for the unit tests.
    
    This will allow `call_setup()` to be refactored in a subsequent commit.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1661

 lib/gs-plugin-loader.c         |  8 ++++++--
 lib/gs-plugin-loader.h         |  4 +++-
 plugins/core/gs-self-test.c    | 21 +++++++++++----------
 plugins/dummy/gs-self-test.c   | 27 ++++++++++++++-------------
 plugins/flatpak/gs-self-test.c | 29 +++++++++++++++--------------
 5 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index a9592ad9b..eecf995a2 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2315,8 +2315,11 @@ plugin_shutdown_cb (GObject      *source_object,
  * and in a controlled way.
  */
 void
-gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
+gs_plugin_loader_setup_again (GsPluginLoader      *plugin_loader,
+                              const gchar * const *allowlist,
+                              const gchar * const *blocklist)
 {
+       g_autoptr(GError) local_error = NULL;
 #ifdef HAVE_SYSPROF
        gint64 begin_time_nsec G_GNUC_UNUSED = SYSPROF_CAPTURE_CURRENT_TIME;
 #endif
@@ -2331,7 +2334,8 @@ gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
        gs_plugin_loader_remove_events (plugin_loader);
 
        /* Start all the plugins setting up again in parallel. */
-       gs_plugin_loader_call_setup (plugin_loader, NULL);
+       gs_plugin_loader_setup (plugin_loader, allowlist, blocklist, NULL, &local_error);
+       g_assert_no_error (local_error);
 
 #ifdef HAVE_SYSPROF
        if (plugin_loader->sysprof_writer != NULL) {
diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h
index 37cef9a2a..383dc3415 100644
--- a/lib/gs-plugin-loader.h
+++ b/lib/gs-plugin-loader.h
@@ -95,7 +95,9 @@ GsApp         *gs_plugin_loader_get_system_app_finish (GsPluginLoader *plugin_loader,
 GsOdrsProvider *gs_plugin_loader_get_odrs_provider     (GsPluginLoader *plugin_loader);
 
 /* only useful from the self tests */
-void            gs_plugin_loader_setup_again           (GsPluginLoader *plugin_loader);
+void            gs_plugin_loader_setup_again           (GsPluginLoader *plugin_loader,
+                                                        const gchar * const *allowlist,
+                                                        const gchar * const *blocklist);
 void            gs_plugin_loader_clear_caches          (GsPluginLoader *plugin_loader);
 GsPlugin       *gs_plugin_loader_find_plugin           (GsPluginLoader *plugin_loader,
                                                         const gchar    *plugin_name);
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index 1830638ca..e60fcbc10 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -15,6 +15,14 @@
 #include "gs-appstream.h"
 #include "gs-test.h"
 
+const gchar * const allowlist[] = {
+       "appstream",
+       "generic-updates",
+       "icons",
+       "os-release",
+       NULL
+};
+
 static void
 gs_plugins_core_search_repo_name_func (GsPluginLoader *plugin_loader)
 {
@@ -26,7 +34,7 @@ gs_plugins_core_search_repo_name_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* force this app to be installed */
        app_tmp = gs_plugin_loader_app_create (plugin_loader, "*/*/yellow/arachne.desktop/*", NULL, &error);
@@ -62,7 +70,7 @@ gs_plugins_core_os_release_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* refine system application */
        app = gs_plugin_loader_get_system_app (plugin_loader, NULL, &error);
@@ -116,7 +124,7 @@ gs_plugins_core_generic_updates_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* create a list with generic apps */
        list = gs_app_list_new ();
@@ -189,13 +197,6 @@ main (int argc, char **argv)
        g_autoptr(GError) error = NULL;
        g_autoptr(GsPluginLoader) plugin_loader = NULL;
        const gchar *xml;
-       const gchar *allowlist[] = {
-               "appstream",
-               "generic-updates",
-               "icons",
-               "os-release",
-               NULL
-       };
 
        /* While we use %G_TEST_OPTION_ISOLATE_DIRS to create temporary directories
         * for each of the tests, we want to use the system MIME registry, assuming
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index b17809e71..618143270 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -15,6 +15,17 @@
 
 #include "gs-test.h"
 
+const gchar * const allowlist[] = {
+       "appstream",
+       "dummy",
+       "generic-updates",
+       "hardcoded-blocklist",
+       "icons",
+       "provenance",
+       "provenance-license",
+       NULL
+};
+
 static guint _status_changed_cnt = 0;
 
 typedef struct {
@@ -98,7 +109,7 @@ gs_plugins_dummy_error_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* update, which should cause an error to be emitted */
        app = gs_app_new ("chiron.desktop");
@@ -471,7 +482,7 @@ gs_plugins_dummy_hang_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* get search result based on addon keyword */
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
@@ -624,7 +635,7 @@ gs_plugins_dummy_limit_parallel_ops_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* get the updates list */
        plugin_job1 = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
@@ -722,16 +733,6 @@ main (int argc, char **argv)
        g_autofree gchar *xml = NULL;
        g_autoptr(GError) error = NULL;
        g_autoptr(GsPluginLoader) plugin_loader = NULL;
-       const gchar *allowlist[] = {
-               "appstream",
-               "dummy",
-               "generic-updates",
-               "hardcoded-blocklist",
-               "icons",
-               "provenance",
-               "provenance-license",
-               NULL
-       };
 
        /* While we use %G_TEST_OPTION_ISOLATE_DIRS to create temporary directories
         * for each of the tests, we want to use the system MIME registry, assuming
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index fcf307a59..4d11ac0be 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -17,6 +17,13 @@
 
 #include "gs-test.h"
 
+const gchar * const allowlist[] = {
+       "appstream",
+       "flatpak",
+       "icons",
+       NULL
+};
+
 static gboolean
 gs_flatpak_test_write_repo_file (const gchar *fn, const gchar *testdir, GFile **file_out, GError **error)
 {
@@ -274,7 +281,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -554,7 +561,7 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -703,7 +710,7 @@ gs_plugins_flatpak_runtime_repo_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* write a flatpakrepo file */
        testdir = gs_test_get_filename (TESTDATADIR, "only-runtime");
@@ -838,7 +845,7 @@ gs_plugins_flatpak_runtime_repo_redundant_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* write a flatpakrepo file */
        testdir = gs_test_get_filename (TESTDATADIR, "only-runtime");
@@ -994,7 +1001,7 @@ gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1090,7 +1097,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1390,7 +1397,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1645,7 +1652,7 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader);
+       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        g_assert_true (gs_plugin_loader_get_enabled (plugin_loader, "flatpak"));
@@ -1891,12 +1898,6 @@ main (int argc, char **argv)
        g_autofree gchar *xml = NULL;
        g_autoptr(GError) error = NULL;
        g_autoptr(GsPluginLoader) plugin_loader = NULL;
-       const gchar *allowlist[] = {
-               "appstream",
-               "flatpak",
-               "icons",
-               NULL
-       };
 
        /* While we use %G_TEST_OPTION_ISOLATE_DIRS to create temporary directories
         * for each of the tests, we want to use the system MIME registry, assuming


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