[gnome-software] Remove any addons that have the same source as the parent app



commit 5376102a8c31a28700f1242466edaab97cc83c4b
Author: Richard Hughes <richard hughsie com>
Date:   Tue Dec 6 14:53:44 2016 +0000

    Remove any addons that have the same source as the parent app
    
    Sometimes applications install plugins with metainfo files as part of the main
    application. This is a problem because we currently strip out any addons from
    the AppStream metadata whilst building that have the same pkgname as the parent
    application.
    
    If we can stop doing this it will save ~30ms per installed metainfo file not in
    the appstream data file as we no longer have to use PackageKit at startup to
    look up the package name. This requires the opposite change in appstream-builder
    but this gnome-software patch is harmless with the old builder logic.

 src/gs-app-private.h   |    2 ++
 src/gs-app.c           |   19 +++++++++++++++++++
 src/gs-plugin-loader.c |   29 +++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-private.h b/src/gs-app-private.h
index 0a83c81..982ac5c 100644
--- a/src/gs-app-private.h
+++ b/src/gs-app-private.h
@@ -31,6 +31,8 @@ void           gs_app_set_priority            (GsApp          *app,
 guint           gs_app_get_priority            (GsApp          *app);
 void            gs_app_set_unique_id           (GsApp          *app,
                                                 const gchar    *unique_id);
+void            gs_app_remove_addon            (GsApp          *app,
+                                                GsApp          *addon);
 
 G_END_DECLS
 
diff --git a/src/gs-app.c b/src/gs-app.c
index 0028fd7..1d55856 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -2698,6 +2698,25 @@ gs_app_add_addon (GsApp *app, GsApp *addon)
 }
 
 /**
+ * gs_app_remove_addon:
+ * @app: a #GsApp
+ * @addon: a #GsApp
+ *
+ * Removes an addon from the list of application addons.
+ *
+ * Since: 3.22
+ **/
+void
+gs_app_remove_addon (GsApp *app, GsApp *addon)
+{
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&app->mutex);
+       g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (GS_IS_APP (addon));
+       g_ptr_array_remove (app->addons, addon);
+       g_hash_table_remove (app->addons_hash, gs_app_get_id (addon));
+}
+
+/**
  * gs_app_get_related:
  * @app: a #GsApp
  *
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 4b42016..779d2df 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -840,6 +840,35 @@ gs_plugin_loader_run_refine (GsPluginLoaderJob *job,
                        goto out;
        }
 
+       /* remove any addons that have the same source as the parent app */
+       for (i = 0; i < gs_app_list_length (list); i++) {
+               g_autoptr(GPtrArray) to_remove = g_ptr_array_new ();
+               GsApp *app = gs_app_list_index (list, i);
+               GPtrArray *addons = gs_app_get_addons (app);
+
+               /* find any apps with the same source */
+               const gchar *pkgname_parent = gs_app_get_source_default (app);
+               if (pkgname_parent == NULL)
+                       continue;
+               for (guint j = 0; j < addons->len; j++) {
+                       GsApp *addon = g_ptr_array_index (addons, j);
+                       if (g_strcmp0 (gs_app_get_source_default (addon),
+                                      pkgname_parent) == 0) {
+                               g_debug ("%s has the same pkgname of %s as %s",
+                                        gs_app_get_unique_id (app),
+                                        pkgname_parent,
+                                        gs_app_get_unique_id (addon));
+                               g_ptr_array_add (to_remove, addon);
+                       }
+               }
+
+               /* remove any addons with the same source */
+               for (guint j = 0; j < to_remove->len; j++) {
+                       GsApp *addon = g_ptr_array_index (to_remove, j);
+                       gs_app_remove_addon (app, addon);
+               }
+       }
+
 out:
        /* now emit all the changed signals */
        for (i = 0; i < gs_app_list_length (freeze_list); i++) {


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