[gnome-software] flatpak: Set the origin correctly for installed bundles



commit bd17e476f89542b6284361a73f9fd6907ff88ad0
Author: Matthew Leeds <matthew leeds endlessm com>
Date:   Thu Jan 23 13:09:05 2020 -0800

    flatpak: Set the origin correctly for installed bundles
    
    If the user opens a .flatpak bundle of an app which is already
    installed, ensure that gs_app_get_origin () returns the correct value
    for the GsApp that gets created, e.g. "hacktml-origin" not "flatpak".
    This fixes an assertion failure in the new unit test for installing
    flatpak bundles.

 plugins/flatpak/gs-flatpak.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 01315e89..1f3ccdff 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2674,6 +2674,8 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
        g_autoptr(GBytes) metadata = NULL;
        g_autoptr(GsApp) app = NULL;
        g_autoptr(FlatpakBundleRef) xref_bundle = NULL;
+       g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
+       const char *origin = NULL;
 
        /* load bundle */
        xref_bundle = flatpak_bundle_ref_new (file, error);
@@ -2683,8 +2685,18 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
                return NULL;
        }
 
+       /* get the origin if it's already installed */
+       installed_ref = flatpak_installation_get_installed_ref (self->installation,
+                                                               flatpak_ref_get_kind (FLATPAK_REF 
(xref_bundle)),
+                                                               flatpak_ref_get_name (FLATPAK_REF 
(xref_bundle)),
+                                                               flatpak_ref_get_arch (FLATPAK_REF 
(xref_bundle)),
+                                                               flatpak_ref_get_branch (FLATPAK_REF 
(xref_bundle)),
+                                                               NULL, NULL);
+       if (installed_ref != NULL)
+               origin = flatpak_installed_ref_get_origin (installed_ref);
+
        /* load metadata */
-       app = gs_flatpak_create_app (self, NULL /* origin */, FLATPAK_REF (xref_bundle));
+       app = gs_flatpak_create_app (self, origin, FLATPAK_REF (xref_bundle));
        if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
                if (gs_flatpak_app_get_ref_name (app) == NULL)
                        gs_flatpak_set_metadata (self, app, FLATPAK_REF (xref_bundle));
@@ -2704,7 +2716,7 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
        /* load AppStream */
        appstream_gz = flatpak_bundle_ref_get_appstream (xref_bundle);
        if (appstream_gz != NULL) {
-               if (!gs_flatpak_refine_appstream_from_bytes (self, app, NULL, appstream_gz,
+               if (!gs_flatpak_refine_appstream_from_bytes (self, app, origin, appstream_gz,
                                                             GS_PLUGIN_REFINE_FLAGS_DEFAULT,
                                                             cancellable, error))
                        return NULL;


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