[gnome-software: 4/6] flatpak: Fix displaying renamed apps




commit 3a14718ab5aece0aec2529608a1709cf4874e0ce
Author: Phaedrus Leeds <mwleeds endlessos org>
Date:   Fri Nov 6 13:39:27 2020 -0800

    flatpak: Fix displaying renamed apps
    
    Currently for apps that have been renamed on Flathub, at least
    org.gnome.iagno for example, the appstream data only exists under the
    new name, so the app doesn't get properly displayed in the updates list
    as it should so it can be updated to the new name. Instead there are
    errors in the log "GsPluginFlatpak no match for ....: no results for
    XPath query" and later "Gs app invalid as no name ..."
    
    So use the appstream data under the new name in such circumstances. This
    is not perfect in that we'll show the new name before the app has
    actually been renamed, but it's certainly better than not showing the
    app at all, and in practice renames are often just to change the app ID.
    
    This makes renamed apps display properly in the Installed and Updates
    lists, but there is still a remaining issue: after updating an app to
    a new name, it doesn't show in the Installed list until after
    gnome-software is closed and restarted.

 plugins/flatpak/gs-flatpak.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index b21df303..10d5bcd2 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2390,6 +2390,40 @@ gs_flatpak_refine_appstream_from_bytes (GsFlatpak *self,
        return TRUE;
 }
 
+static XbNode *
+get_renamed_component (GsFlatpak *self,
+                      GsApp *app,
+                      XbSilo *silo)
+{
+       const gchar *origin = gs_app_get_origin (app);
+       const gchar *renamed_to;
+       g_autofree gchar *xpath = NULL;
+       g_autofree gchar *source_safe = NULL;
+       g_autoptr(FlatpakRemoteRef) remote_ref = NULL;
+
+       remote_ref = flatpak_installation_fetch_remote_ref_sync (self->installation,
+                                                                origin,
+                                                                gs_flatpak_app_get_ref_kind (app),
+                                                                gs_flatpak_app_get_ref_name (app),
+                                                                gs_flatpak_app_get_ref_arch (app),
+                                                                gs_app_get_branch (app),
+                                                                NULL, NULL);
+       if (remote_ref == NULL)
+               return NULL;
+
+       renamed_to = flatpak_remote_ref_get_eol_rebase (remote_ref);
+       if (renamed_to == NULL)
+               return NULL;
+
+       /* FIXME: This libxmlb query will need reworking after this PR lands:
+        * https://github.com/hughsie/libxmlb/pull/67
+        */
+       source_safe = xb_string_escape (renamed_to);
+       xpath = g_strdup_printf ("components[@origin='%s']/component/bundle[@type='flatpak'][text()='%s']/..",
+                                origin, source_safe);
+       return xb_silo_query_first (silo, xpath, NULL);
+}
+
 static gboolean
 gs_flatpak_refine_appstream (GsFlatpak *self,
                             GsApp *app,
@@ -2413,6 +2447,12 @@ gs_flatpak_refine_appstream (GsFlatpak *self,
        xpath = g_strdup_printf ("components[@origin='%s']/component/bundle[@type='flatpak'][text()='%s']/..",
                                 origin, source_safe);
        component = xb_silo_query_first (silo, xpath, &error_local);
+
+       /* If the app was renamed, use the appstream data from the new name;
+        * usually it will not exist under the old name */
+       if (component == NULL && gs_flatpak_app_get_ref_kind (app) == FLATPAK_REF_KIND_APP)
+               component = get_renamed_component (self, app, silo);
+
        if (component == NULL) {
                g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
                g_autoptr(GBytes) appstream_gz = NULL;


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