[gnome-software/wip/hughsie/wildcarded-metadata] Copy metadata from wildcard GsApp objects to concrete GsApps



commit 450f874d9b24af4ece216857b670ea71e2c55f93
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 14 09:43:12 2018 +0100

    Copy metadata from wildcard GsApp objects to concrete GsApps
    
    This allows us to set a wildcard that matches on some metadata (for instance,
    GnomeSoftware::FeatureTile-css) and this allows us to preserve the data without
    having to re-resolve the metadata in the concrete GsApp.
    
    This allows us to ignore the problem where the system appstream plugin is no
    longer refining flatpaks, and thus higher priority GsApps were not getting the
    system-defined feature tile CSS metadata set.

 lib/gs-app.c                       | 21 +++++++++++++++++++++
 lib/gs-app.h                       |  3 +++
 plugins/core/gs-appstream.c        |  1 +
 plugins/core/gs-plugin-appstream.c |  1 +
 plugins/flatpak/gs-flatpak.c       |  1 +
 5 files changed, 27 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index a3b0454d..ebc8e277 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -4537,4 +4537,25 @@ gs_app_get_packaging_format (GsApp *app)
        return g_strdup (bundle_kind_ui);
 }
 
+/**
+ * gs_app_subsume_metadata:
+ * @app: a #GsApp
+ * @donor: another #GsApp
+ *
+ * Copies any metadata from @donor to @app.
+ *
+ * Since: 3.32
+ **/
+void
+gs_app_subsume_metadata (GsApp *app, GsApp *donor)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (donor);
+       g_autoptr(GList) keys = g_hash_table_get_keys (priv->metadata);
+       for (GList *l = keys; l != NULL; l = l->next) {
+               const gchar *key = l->data;
+               const gchar *value = gs_app_get_metadata_item (donor, key);
+               gs_app_set_metadata (app, key, value);
+       }
+}
+
 /* vim: set noexpandtab: */
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 0b38c101..b59736a9 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -320,6 +320,9 @@ gboolean     gs_app_is_installed            (GsApp          *app);
 gboolean        gs_app_is_updatable            (GsApp          *app);
 gchar          *gs_app_get_origin_ui           (GsApp          *app);
 gchar          *gs_app_get_packaging_format    (GsApp          *app);
+void            gs_app_subsume_metadata        (GsApp          *app,
+                                                GsApp          *donor);
+
 G_END_DECLS
 
 #endif /* __GS_APP_H */
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 3efc679e..370a1720 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -1088,6 +1088,7 @@ gs_appstream_add_featured (GsPlugin *plugin,
                        continue;
                app = gs_app_new (as_app_get_id (item));
                gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+               gs_appstream_copy_metadata (app, item);
                gs_app_list_add (list, app);
        }
        return TRUE;
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 88c55c55..d20beecc 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -591,6 +591,7 @@ gs_plugin_refine_wildcard (GsPlugin *plugin,
                new = gs_appstream_create_app (plugin, item, error);
                if (new == NULL)
                        return FALSE;
+               gs_app_subsume_metadata (new, app);
                gs_app_list_add (list, new);
        }
 
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index ecbe1ed5..4059a8ae 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1991,6 +1991,7 @@ gs_flatpak_refine_wildcard (GsFlatpak *self, GsApp *app,
                gs_flatpak_claim_app (self, new);
                if (!gs_flatpak_refine_app (self, new, flags, cancellable, error))
                        return FALSE;
+               gs_app_subsume_metadata (new, app);
                gs_app_list_add (list, new);
        }
        return TRUE;


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