File 0011-flatpak-installation-Handle-an-unconfigured-remote-when-listing-remotes.patch of Package flatpak.25785

From 7c29654abfc4cdcf48aa7df6f9d23a8e552dfaab Mon Sep 17 00:00:00 2001
From: Philip Withnall <withnall@endlessm.com>
Date: Thu, 25 Jul 2019 17:25:12 +0100
Subject: [PATCH] flatpak-installation: Handle an unconfigured remote when
 listing remotes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This prevents a crash in flatpak_installation_list_remotes_by_type() if
the `FlatpakDir` can’t ensure it has a repo configured.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #3028
Approved by: alexlarsson

(cherry picked from commit 791f31898b629bad5f6e29392be260fb06fb871d)
(cherry picked from commit 12cecc852c657848cce276e5b1255d638145f039)

Closes: #3115
Approved by: alexlarsson
---
 common/flatpak-installation.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/flatpak-installation.c b/common/flatpak-installation.c
index 5fef0e633..8e8420f20 100644
--- a/common/flatpak-installation.c
+++ b/common/flatpak-installation.c
@@ -1185,7 +1185,8 @@ flatpak_installation_list_installed_refs_for_update (FlatpakInstallation *self,
 /* Find all USB and LAN repositories which share the same collection ID as
  * @remote_name, and add a #FlatpakRemote to @remotes for each of them. The caller
  * must initialise @remotes. Returns %TRUE without modifying @remotes if the
- * given remote doesn’t have a collection ID configured.
+ * given remote doesn’t have a collection ID configured or if the @dir doesn’t
+ * have a repo.
  *
  * FIXME: If this were async, the parallelisation could be handled in the caller. */
 static gboolean
@@ -1197,6 +1198,7 @@ list_remotes_for_configured_remote (FlatpakInstallation *self,
                                     GCancellable        *cancellable,
                                     GError             **error)
 {
+  OstreeRepo *repo;
   g_autofree gchar *collection_id = NULL;
   OstreeCollectionRef ref;
   OstreeCollectionRef ref2;
@@ -1216,8 +1218,12 @@ list_remotes_for_configured_remote (FlatpakInstallation *self,
       !types_filter[FLATPAK_REMOTE_TYPE_LAN])
     return TRUE;
 
+  repo = flatpak_dir_get_repo (dir);
+  if (repo == NULL)
+    return TRUE;
+
   /* Find the collection ID for @remote_name, or bail if there is none. */
-  if (!ostree_repo_get_remote_option (flatpak_dir_get_repo (dir),
+  if (!ostree_repo_get_remote_option (repo,
                                       remote_name, "collection-id",
                                       NULL, &collection_id, error))
     return FALSE;
@@ -1261,7 +1267,7 @@ list_remotes_for_configured_remote (FlatpakInstallation *self,
         }
     }
 
-  ostree_repo_find_remotes_async (flatpak_dir_get_repo (dir),
+  ostree_repo_find_remotes_async (repo,
                                   (const OstreeCollectionRef * const *) refs,
                                   NULL,  /* no options */
                                   finders,
@@ -1273,7 +1279,7 @@ list_remotes_for_configured_remote (FlatpakInstallation *self,
   while (result == NULL)
     g_main_context_iteration (context, TRUE);
 
-  results = ostree_repo_find_remotes_finish (flatpak_dir_get_repo (dir), result, error);
+  results = ostree_repo_find_remotes_finish (repo, result, error);
 
   if (types_filter[FLATPAK_REMOTE_TYPE_LAN])
     ostree_repo_finder_avahi_stop (OSTREE_REPO_FINDER_AVAHI (finder_avahi));
openSUSE Build Service is sponsored by