flatpak-installation: Handle an unconfigured remote when listing remotes

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 791f31898b)
(cherry picked from commit 12cecc852c)

Closes: #3115
Approved by: alexlarsson
This commit is contained in:
Philip Withnall
2019-07-25 17:25:12 +01:00
committed by Atomic Bot
parent 843fb75ebd
commit 7c29654abf

View File

@@ -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 doesnt have a collection ID configured.
* given remote doesnt have a collection ID configured or if the @dir doesnt
* 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));