Blob Blame History Raw
From 3b305e27d1c0f51f2dc42bb9ad58eb90396f44c4 Mon Sep 17 00:00:00 2001
From: Joaquim Rocha <jrocha@endlessm.com>
Date: Sat, 1 Jul 2017 01:33:00 +0200
Subject: [PATCH] flatpak: Set the correct origin when installing a flatpakref

When installing a flatpakref, part of the process is to install its
ref file, and the code was assuming that this installation always
results in a new remote (named as app_name-origin). However, if there
is already a remote with the same URI as the one coming from the ref
file, it will not add the new one in order to avoid redudancy.

Since the GsApp representing the one in the flatpakref was being
assigned the "app_name-origin" as its origin, it would fail to install
later because this expected origin may not exist (as explained above).

To fix this, once the ref file is installed, we get the resulting
remote's name (i.e. a new one or the existing one) and override the
app's origin with it, which will allow the installation to succeed.
---
 src/plugins/gs-flatpak.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index c5a0df3ddc03..55ebba169fb7 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -2513,6 +2513,14 @@ gs_flatpak_app_install (GsFlatpak *self,
 			return FALSE;
 		}
 
+		/* the installation of the ref file above will not create a new remote for
+		 * the app if its URL is already configured as another remote, thus we
+		 * need to update the app origin to match that or it may end up with
+		 * an nonexistent origin; and we first need to set the origin to NULL to
+		 * circumvent the safety check... */
+		gs_app_set_origin (app, NULL);
+		gs_app_set_origin (app, flatpak_remote_ref_get_remote_name (xref2));
+
 		/* update search tokens for new remote */
 		if (!gs_flatpak_refresh_appstream (self, G_MAXUINT, 0, cancellable, error))
 			return FALSE;
-- 
1.8.3.1