[gnome-software/gnome-3-20] Make all the plugins more threadsafe



commit ce913f1825a01e75251398aee903d819eae26d23
Author: Richard Hughes <richard hughsie com>
Date:   Thu Apr 14 12:46:26 2016 +0100

    Make all the plugins more threadsafe
    
    Writelock the GRWLock during setup() and refresh(), and readlock during all
    other operations. Also unconditionally call setup() when loading the plugin
    rather than leaving the plugin to do the GOnce or GMutex locking correctly.

 src/gs-plugin-loader.c                     |   56 ++++++++++++++++++++++++
 src/gs-plugin.h                            |    7 +++
 src/plugins/gs-plugin-appstream.c          |   52 +---------------------
 src/plugins/gs-plugin-fwupd.c              |   38 +---------------
 src/plugins/gs-plugin-packagekit-history.c |   15 +-----
 src/plugins/gs-plugin-systemd-updates.c    |   16 +------
 src/plugins/gs-plugin-xdg-app.c            |   63 ++-------------------------
 7 files changed, 80 insertions(+), 167 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index f07d60d..a6dfb1b 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -354,7 +354,9 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
                ptask2 = as_profile_start (priv->profile,
                                           "GsPlugin::%s(%s)",
                                           plugin->name, function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &list, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -616,7 +618,9 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, app, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1503,8 +1507,10 @@ gs_plugin_loader_search_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1665,8 +1671,10 @@ gs_plugin_loader_search_files_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1828,8 +1836,10 @@ gs_plugin_loader_search_what_provides_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, values, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -1997,8 +2007,10 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -2128,8 +2140,10 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->category, &state->list,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -2455,8 +2469,10 @@ gs_plugin_loader_review_action_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          state->function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->app, state->review,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   state->function_name, plugin->name,
@@ -2860,7 +2876,9 @@ gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                plugin_func (plugin);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 }
@@ -3027,6 +3045,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->scale = gs_plugin_loader_get_scale (plugin_loader);
        g_debug ("opened plugin %s: %s", filename, plugin->name);
 
+       /* rwlock */
+       g_rw_lock_init (&plugin->rwlock);
+
        /* add to array */
        g_ptr_array_add (priv->plugins, plugin);
        return plugin;
@@ -3203,6 +3224,34 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
        /* run the plugins */
        gs_plugin_loader_run (plugin_loader, "gs_plugin_initialize");
 
+       /* run setup */
+       for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginSetupFunc plugin_func = NULL;
+               const gchar *function_name = "gs_plugin_setup";
+               gboolean ret;
+               g_autoptr(AsProfileTask) ptask2 = NULL;
+               g_autoptr(GError) error_local = NULL;
+
+               /* run setup() if it exists */
+               plugin = g_ptr_array_index (priv->plugins, i);
+               ret = g_module_symbol (plugin->module,
+                                      function_name,
+                                      (gpointer *) &plugin_func);
+               if (!ret)
+                       continue;
+               ptask2 = as_profile_start (priv->profile,
+                                          "GsPlugin::%s(%s)",
+                                          plugin->name,
+                                          function_name);
+               g_rw_lock_writer_lock (&plugin->rwlock);
+               ret = plugin_func (plugin, NULL, &error_local);
+               g_rw_lock_writer_unlock (&plugin->rwlock);
+               if (!ret) {
+                       g_debug ("disabling %s as setup failed: %s",
+                                plugin->name, error_local->message);
+               }
+       }
+
        /* now we can load the install-queue */
        if (!load_install_queue (plugin_loader, error))
                return FALSE;
@@ -3237,6 +3286,7 @@ gs_plugin_loader_plugin_free (GsPlugin *plugin)
 {
        g_free (plugin->priv);
        g_free (plugin->name);
+       g_rw_lock_clear (&plugin->rwlock);
        g_object_unref (plugin->profile);
        g_object_unref (plugin->soup_session);
        g_module_close (plugin->module);
@@ -3494,7 +3544,9 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_writer_lock (&plugin->rwlock);
                ret = plugin_func (plugin, cache_age, flags, cancellable, &error_local);
+               g_rw_lock_writer_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -3634,8 +3686,10 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, &state->list, state->filename,
                                   cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
@@ -3777,7 +3831,9 @@ gs_plugin_loader_offline_update_thread_cb (GTask *task,
                                          "GsPlugin::%s(%s)",
                                          plugin->name,
                                          function_name);
+               g_rw_lock_reader_lock (&plugin->rwlock);
                ret = plugin_func (plugin, state->list, cancellable, &error_local);
+               g_rw_lock_reader_unlock (&plugin->rwlock);
                if (!ret) {
                        g_warning ("failed to call %s on %s: %s",
                                   function_name, plugin->name,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index ae70bb3..dbab3c6 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -77,6 +77,7 @@ struct GsPlugin {
        gpointer                 updates_changed_user_data;
        AsProfile               *profile;
        SoupSession             *soup_session;
+       GRWLock                  rwlock;
 };
 
 typedef enum {
@@ -127,6 +128,9 @@ typedef enum {
 typedef const gchar    *(*GsPluginGetNameFunc)         (void);
 typedef const gchar    **(*GsPluginGetDepsFunc)        (GsPlugin       *plugin);
 typedef void            (*GsPluginFunc)                (GsPlugin       *plugin);
+typedef gboolean        (*GsPluginSetupFunc)           (GsPlugin       *plugin,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 typedef gboolean        (*GsPluginSearchFunc)          (GsPlugin       *plugin,
                                                         gchar          **value,
                                                         GList          **list,
@@ -214,6 +218,9 @@ gboolean     gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
 const gchar    **gs_plugin_order_after                 (GsPlugin       *plugin);
+gboolean        gs_plugin_setup                        (GsPlugin       *plugin,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 gboolean        gs_plugin_add_installed                (GsPlugin       *plugin,
                                                         GList          **list,
                                                         GCancellable   *cancellable,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 9120fd7..428752f 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -42,8 +42,6 @@
 
 struct GsPluginPrivate {
        AsStore                 *store;
-       GMutex                   store_mutex;
-       gboolean                 done_init;
 };
 
 /**
@@ -75,7 +73,6 @@ void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
-       g_mutex_init (&plugin->priv->store_mutex);
        plugin->priv->store = as_store_new ();
        as_store_set_watch_flags (plugin->priv->store,
                                  AS_STORE_WATCH_FLAG_ADDED |
@@ -101,7 +98,6 @@ void
 gs_plugin_destroy (GsPlugin *plugin)
 {
        g_object_unref (plugin->priv->store);
-       g_mutex_clear (&plugin->priv->store_mutex);
 }
 
 /**
@@ -152,12 +148,10 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
 }
 
 /**
- * gs_plugin_appstream_startup:
- *
- * This must be called with plugin->priv->store_mutex held.
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        AsApp *app;
        GPtrArray *items;
@@ -166,13 +160,6 @@ gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
        guint *perc;
        guint i;
        g_autoptr(GHashTable) origins = NULL;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       /* already done */
-       if (plugin->priv->done_init)
-               return TRUE;
-
-       ptask = as_profile_start_literal (plugin->profile, "appstream::startup");
 
        /* Parse the XML */
        if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
@@ -241,7 +228,6 @@ gs_plugin_appstream_startup (GsPlugin *plugin, GError **error)
        }
 
        /* rely on the store keeping itself updated */
-       plugin->priv->done_init = TRUE;
        return TRUE;
 }
 
@@ -319,11 +305,6 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
        AsApp *item;
        GPtrArray *array;
        guint i;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find any upgrades */
        array = as_store_get_apps (plugin->priv->store);
@@ -357,14 +338,7 @@ gs_plugin_refine (GsPlugin *plugin,
        gboolean found = FALSE;
        GList *l;
        GsApp *app;
-       g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
 
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
-
-       ptask = as_profile_start_literal (plugin->profile, "appstream::refine");
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                if (!gs_plugin_refine_from_id (plugin, app, &found, error))
@@ -396,11 +370,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* get the two search terms */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-category-apps");
@@ -490,11 +459,6 @@ gs_plugin_add_search (GsPlugin *plugin,
        gboolean ret = TRUE;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* search categories for the search term */
        ptask = as_profile_start_literal (plugin->profile, "appstream::search");
@@ -524,11 +488,6 @@ gs_plugin_add_installed (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* search categories for the search term */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add_installed");
@@ -605,11 +564,6 @@ gs_plugin_add_categories (GsPlugin *plugin,
        GPtrArray *array;
        guint i;
        g_autoptr(AsProfileTask) ptask = NULL;
-       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
-
-       /* load XML files */
-       if (!gs_plugin_appstream_startup (plugin, error))
-               return FALSE;
 
        /* find out how many packages are in each category */
        ptask = as_profile_start_literal (plugin->profile, "appstream::add-categories");
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 2f6b574..c686449 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -111,10 +111,10 @@ gs_plugin_fwupd_changed_cb (GDBusProxy *proxy,
 }
 
 /**
- * gs_plugin_startup:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        gsize len;
        g_autofree gchar *data = NULL;
@@ -413,14 +413,6 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
        g_autoptr(GVariantIter) iter = NULL;
        g_autoptr(GVariant) val = NULL;
 
-       /* set up plugin */
-       if (plugin->priv->proxy == NULL) {
-               if (!gs_plugin_startup (plugin, cancellable, error))
-                       return FALSE;
-       }
-       if (plugin->priv->proxy == NULL)
-               return TRUE;
-
        /* get historical updates */
        val = g_dbus_proxy_call_sync (plugin->priv->proxy,
                                      "GetResults",
@@ -475,14 +467,6 @@ gs_plugin_add_updates (GsPlugin *plugin,
        g_autoptr(GVariantIter) iter = NULL;
        g_autoptr(GVariant) val = NULL;
 
-       /* set up plugin */
-       if (plugin->priv->proxy == NULL) {
-               if (!gs_plugin_startup (plugin, cancellable, error))
-                       return FALSE;
-       }
-       if (plugin->priv->proxy == NULL)
-               return TRUE;
-
        /* get current list of updates */
        val = g_dbus_proxy_call_sync (plugin->priv->proxy,
                                      "GetUpdates",
@@ -729,14 +713,6 @@ gs_plugin_refresh (GsPlugin *plugin,
        const gchar *tmp;
        guint i;
 
-       /* set up plugin */
-       if (plugin->priv->proxy == NULL) {
-               if (!gs_plugin_startup (plugin, cancellable, error))
-                       return FALSE;
-       }
-       if (plugin->priv->proxy == NULL)
-               return TRUE;
-
        /* get the metadata and signature file */
        if (!gs_plugin_fwupd_check_lvfs_metadata (plugin, cache_age, cancellable, error))
                return FALSE;
@@ -982,14 +958,6 @@ gs_plugin_fwupd_unlock (GsPlugin *plugin,
 {
        g_autoptr(GVariant) val = NULL;
 
-       /* set up plugin */
-       if (plugin->priv->proxy == NULL) {
-               if (!gs_plugin_startup (plugin, cancellable, error))
-                       return FALSE;
-       }
-       if (plugin->priv->proxy == NULL)
-               return TRUE;
-
        /* unlock device */
        val = g_dbus_proxy_call_sync (plugin->priv->proxy,
                                      "Unlock",
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index fc545ac..2e37c9e 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -34,7 +34,6 @@
  */
 
 struct GsPluginPrivate {
-       gsize                    loaded;
        GDBusConnection         *connection;
 };
 
@@ -133,10 +132,10 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
 }
 
 /**
- * gs_plugin_load:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_load (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        plugin->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
                                                   cancellable,
@@ -161,14 +160,6 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
        g_autoptr(GVariant) result = NULL;
        g_autoptr(GVariant) tuple = NULL;
 
-       /* already loaded */
-       if (g_once_init_enter (&plugin->priv->loaded)) {
-               ret = gs_plugin_load (plugin, cancellable, error);
-               g_once_init_leave (&plugin->priv->loaded, TRUE);
-               if (!ret)
-                       return FALSE;
-       }
-
        /* get an array of package names */
        package_names = g_new0 (const gchar *, g_list_length (list) + 1);
        for (l = list; l != NULL; l = l->next) {
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index 84be358..952511a 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -35,7 +35,6 @@
 
 struct GsPluginPrivate {
        GFileMonitor            *monitor;
-       gsize                    done_init;
 };
 
 /**
@@ -80,10 +79,10 @@ gs_plugin_systemd_updates_changed_cb (GFileMonitor *monitor,
 }
 
 /**
- * gs_plugin_startup:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        plugin->priv->monitor = pk_offline_get_prepared_monitor (cancellable, error);
        if (plugin->priv->monitor == NULL)
@@ -103,19 +102,10 @@ gs_plugin_add_updates (GsPlugin *plugin,
                       GCancellable *cancellable,
                       GError **error)
 {
-       gboolean ret;
        guint i;
        g_autoptr(GError) error_local = NULL;
        g_auto(GStrv) package_ids = NULL;
 
-       /* watch the file in case it comes or goes */
-       if (g_once_init_enter (&plugin->priv->done_init)) {
-               ret = gs_plugin_startup (plugin, cancellable, error);
-               g_once_init_leave (&plugin->priv->done_init, TRUE);
-               if (!ret)
-                       return FALSE;
-       }
-
        /* get the id's if the file exists */
        package_ids = pk_offline_get_prepared_ids (&error_local);
        if (package_ids == NULL) {
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 152e4d2..2c7239d 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -252,20 +252,15 @@ gs_plugin_refresh_appstream (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_ensure_installation:
+ * gs_plugin_setup:
  */
-static gboolean
-gs_plugin_ensure_installation (GsPlugin *plugin,
-                              GCancellable *cancellable,
-                              GError **error)
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        g_autofree gchar *install_path = NULL;
        g_autoptr(AsProfileTask) ptask = NULL;
        g_autoptr(GFile) install_file = NULL;
 
-       if (plugin->priv->installation != NULL)
-               return TRUE;
-
        /* If we're running INSIDE the xdg-app environment we'll have the
         * env var XDG_DATA_HOME set to "~/.var/app/org.gnome.Software/data"
         * so specify the path manually to get the real data */
@@ -461,10 +456,6 @@ gs_plugin_add_installed (GsPlugin *plugin,
        g_autoptr(GPtrArray) xrefs = NULL;
        guint i;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* if we've never ever run before, get the AppStream data */
        if (!gs_plugin_refresh_appstream (plugin,
                                          G_MAXUINT,
@@ -512,10 +503,6 @@ gs_plugin_add_sources (GsPlugin *plugin,
        g_autoptr(GPtrArray) xremotes = NULL;
        guint i;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
                                                      cancellable,
                                                      error);
@@ -560,10 +547,6 @@ gs_plugin_add_updates (GsPlugin *plugin,
        guint i;
        g_autoptr(GPtrArray) xrefs = NULL;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* get all the installed apps (no network I/O) */
        xrefs = xdg_app_installation_list_installed_refs (plugin->priv->installation,
                                                          cancellable,
@@ -622,14 +605,6 @@ gs_plugin_refresh (GsPlugin *plugin,
        if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
-       /* update AppStream metadata */
-       if (!gs_plugin_refresh_appstream (plugin, cache_age, cancellable, error))
-               return FALSE;
-
        /* use helper: FIXME: new()&ref? */
        helper.plugin = plugin;
 
@@ -685,12 +660,8 @@ gs_plugin_refine_item_origin_ui (GsPlugin *plugin,
        if (origin != NULL)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin-ui");
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* find list of remotes */
+       ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin-ui");
        xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
                                                      cancellable,
                                                      error);
@@ -725,12 +696,8 @@ gs_plugin_refine_item_origin (GsPlugin *plugin,
        if (gs_app_get_origin (app) != NULL)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin");
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* ensure metadata exists */
+       ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin");
        if (!gs_plugin_refine_item_metadata (plugin, app, cancellable, error))
                return FALSE;
 
@@ -1185,10 +1152,6 @@ gs_plugin_refine (GsPlugin *plugin,
        GList *l;
        GsApp *app;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
                if (!gs_plugin_refine_item (plugin, app, flags, cancellable, error))
@@ -1212,10 +1175,6 @@ gs_plugin_launch (GsPlugin *plugin,
        if (g_strcmp0 (gs_app_get_management_plugin (app), "XgdApp") != 0)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        branch = gs_app_get_xdgapp_branch (app);
        if (branch == NULL)
                branch = "master";
@@ -1243,10 +1202,6 @@ gs_plugin_app_remove (GsPlugin *plugin,
        if (g_strcmp0 (gs_app_get_management_plugin (app), "XgdApp") != 0)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* use helper: FIXME: new()&ref? */
        helper.app = app;
        helper.plugin = plugin;
@@ -1278,10 +1233,6 @@ gs_plugin_app_install (GsPlugin *plugin,
        if (g_strcmp0 (gs_app_get_management_plugin (app), "XgdApp") != 0)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* ensure we have metadata and state */
        if (!gs_plugin_refine_item (plugin, app, 0, cancellable, error))
                return FALSE;
@@ -1381,10 +1332,6 @@ gs_plugin_app_update (GsPlugin *plugin,
        if (g_strcmp0 (gs_app_get_management_plugin (app), "XgdApp") != 0)
                return TRUE;
 
-       /* ensure we can set up the repo */
-       if (!gs_plugin_ensure_installation (plugin, cancellable, error))
-               return FALSE;
-
        /* use helper: FIXME: new()&ref? */
        helper.app = app;
        helper.plugin = plugin;


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