[gnome-software] flatpak: Match origin when searching appstream



commit 73f3f421d422b7b953c5dff50d946b2e7db482ca
Author: Kalev Lember <klember redhat com>
Date:   Sat Jan 26 15:50:04 2019 +0100

    flatpak: Match origin when searching appstream
    
    When parsing system installed appstream data for packages we usually
    have one appstream file that covers multiple repos (e.g.
    /usr/share/app-info/xmls/fedora.xml.gz and "fedora", "updates",
    "updates-testing" repos). In this case, when parsing the appstream we
    can't set app origin based on the appstream origin as there is no
    one-to-one mapping from appstream origin to the repo where the package
    actually comes from.
    
    For flatpaks, however, we always have per-remote appstream data and we
    need to keep track of the origin to match the correct app from the
    correct remote. If we don't do that then we end up refining flatpak apps
    with the first entry that appstream finds, which may be from a wrong
    remote.
    
    This is harmless when only one repo provides each flatpak app, but as
    soon as we have two (e.g. Flathub and Fedora) we need to make sure to
    match the correct appstream entry with the correct flatpak.
    
    This regressed in commit d364825 that took out the origin adding in
    gs_appstream_create_app(). This commit now adds it back and makes it
    work again for the new libxmlb parsing code.
    
    Partially fixes: https://gitlab.gnome.org/GNOME/gnome-software/issues/547

 plugins/core/gs-appstream.c  | 10 ++++++++++
 plugins/flatpak/gs-flatpak.c |  5 +++--
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index d5c6f449..8b0039f6 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -860,6 +860,16 @@ gs_appstream_refine_app (GsPlugin *plugin,
                }
        }
 
+       /* set origin for flatpaks */
+       if (gs_app_get_origin (app) == NULL &&
+           gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_FLATPAK) {
+               g_autoptr(XbNode) parent = xb_node_get_parent (component);
+               if (parent != NULL) {
+                       tmp = xb_node_get_attr (parent, "origin");
+                       gs_app_set_origin (app, tmp);
+               }
+       }
+
        /* set addons */
        if (refine_flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS) {
                if (!gs_appstream_refine_add_addons (plugin, app, silo, error))
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 0b1901fb..516c8981 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2099,14 +2099,15 @@ gs_flatpak_refine_appstream (GsFlatpak *self,
                             GError **error)
 {
        const gchar *id = gs_app_get_id (app);
+       const gchar *origin = gs_app_get_origin (app);
        g_autofree gchar *xpath = NULL;
        g_autoptr(XbNode) component = NULL;
 
        if (id == NULL)
                return TRUE;
 
-       /* find using ID */
-       xpath = g_strdup_printf ("components/component/id[text()='%s']/..", id);
+       /* find using ID and origin */
+       xpath = g_strdup_printf ("components[@origin='%s']/component/id[text()='%s']/..", origin, id);
        component = xb_silo_query_first (silo, xpath, NULL);
        if (component == NULL)
                return TRUE;


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