mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-24 23:58:10 -05:00
common: Properly handle empty arrays of P2P results
ostree_repo_find_remotes_finish() can return an empty array of OstreeRepoFinderResults without setting @error and expects the caller to check for this before doing a pull. Currently in a few different places Flatpak does not check if the array is empty after calling ostree_repo_find_remotes_finish() which leads to a critical warning in ostree_repo_pull_from_remotes_async() which expects a non-empty results array. This is causing one of the unit tests to fail. So properly handle the case of an empty results array in each place it can occur. In most places it's an error condition so the error pointer is set appropriately. In list_remotes_for_configured_remote() it's not an error because there may legitimately be no LAN/USB remotes available, so in that case just properly handle the case of (results == NULL). Also, add a debug statement in flatpak_dir_do_resolve_p2p_refs() since we're now building a string of the refs being resolved. Closes: #2705 Approved by: alexlarsson
This commit is contained in:
committed by
Atomic Bot
parent
6cfad442c5
commit
b8a3075d84
@@ -3686,6 +3686,7 @@ flatpak_dir_do_resolve_p2p_refs (FlatpakDir *self,
|
||||
g_auto(GLnxLockFile) child_repo_lock = { 0, };
|
||||
g_autoptr(GFile) user_cache_dir = NULL;
|
||||
g_autoptr(FlatpakTempDir) child_repo_tmp_dir = NULL;
|
||||
g_autoptr(GString) refs_str = NULL;
|
||||
int i;
|
||||
|
||||
main_context = flatpak_main_context_new_default ();
|
||||
@@ -3693,11 +3694,18 @@ flatpak_dir_do_resolve_p2p_refs (FlatpakDir *self,
|
||||
if (with_commit_ids)
|
||||
commit_ids_to_fetch = g_ptr_array_new ();
|
||||
|
||||
refs_str = g_string_new ("");
|
||||
for (i = 0; datas[i] != NULL; i++)
|
||||
{
|
||||
FlatpakDirResolveData *data = datas[i];
|
||||
FlatpakDirResolve *resolve = data->resolve;
|
||||
|
||||
if (i != 0)
|
||||
g_string_append (refs_str, ", ");
|
||||
g_string_append_printf (refs_str, "(%s, %s)",
|
||||
data->collection_ref.collection_id,
|
||||
data->collection_ref.ref_name);
|
||||
|
||||
g_ptr_array_add (collection_refs_to_fetch, &data->collection_ref);
|
||||
if (commit_ids_to_fetch)
|
||||
{
|
||||
@@ -3708,6 +3716,8 @@ flatpak_dir_do_resolve_p2p_refs (FlatpakDir *self,
|
||||
|
||||
g_ptr_array_add (collection_refs_to_fetch, NULL);
|
||||
|
||||
g_debug ("Resolving these collection-refs: [%s]", refs_str->str);
|
||||
|
||||
g_variant_builder_init (&find_builder, G_VARIANT_TYPE ("a{sv}"));
|
||||
if (commit_ids_to_fetch)
|
||||
g_variant_builder_add (&find_builder, "{s@v}", "override-commit-ids",
|
||||
@@ -3743,6 +3753,9 @@ flatpak_dir_do_resolve_p2p_refs (FlatpakDir *self,
|
||||
if (results == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (results[0] == NULL)
|
||||
return flatpak_fail (error, _("No remotes found which provide these refs: [%s]"), refs_str->str);
|
||||
|
||||
/* Drop from the results all ops that are no-op updates */
|
||||
for (i = 0; datas[i] != NULL; i++)
|
||||
{
|
||||
@@ -4477,7 +4490,13 @@ repo_pull (OstreeRepo *self,
|
||||
results_to_fetch = (const OstreeRepoFinderResult * const *) results;
|
||||
}
|
||||
|
||||
if (results_to_fetch != NULL)
|
||||
if (results_to_fetch != NULL && results_to_fetch[0] == NULL)
|
||||
{
|
||||
flatpak_fail (error, _("No remotes found which provide the ref (%s, %s)"),
|
||||
collection_ref.collection_id, collection_ref.ref_name);
|
||||
res = FALSE;
|
||||
}
|
||||
else if (results_to_fetch != NULL)
|
||||
{
|
||||
GVariantBuilder pull_builder, ref_keyring_map_builder;
|
||||
g_autoptr(GVariant) pull_options = NULL;
|
||||
@@ -5257,24 +5276,25 @@ flatpak_dir_pull (FlatpakDir *self,
|
||||
* below won't need to fetch the metadata. For an explanation of the
|
||||
* attack we're protecting against see
|
||||
* https://github.com/flatpak/flatpak/issues/1447#issuecomment-445347590 */
|
||||
{
|
||||
OstreeRepoPullFlags metadata_pull_flags = flags | OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY;
|
||||
/*TODO: Use OSTREE_REPO_PULL_FLAGS_MIRROR for all collection-ref pulls */
|
||||
metadata_pull_flags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
|
||||
if (!repo_pull (repo, state->remote_name,
|
||||
NULL, ref, NULL, results,
|
||||
flatpak_flags, metadata_pull_flags,
|
||||
progress, cancellable, error))
|
||||
{
|
||||
g_prefix_error (error, _("While pulling %s from remote %s: "), ref, state->remote_name);
|
||||
goto out;
|
||||
}
|
||||
if (results[0] != NULL)
|
||||
{
|
||||
OstreeRepoPullFlags metadata_pull_flags = flags | OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY;
|
||||
/*TODO: Use OSTREE_REPO_PULL_FLAGS_MIRROR for all collection-ref pulls */
|
||||
metadata_pull_flags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
|
||||
if (!repo_pull (repo, state->remote_name,
|
||||
NULL, ref, NULL, results,
|
||||
flatpak_flags, metadata_pull_flags,
|
||||
progress, cancellable, error))
|
||||
{
|
||||
g_prefix_error (error, _("While pulling %s from remote %s: "), ref, state->remote_name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!flatpak_repo_resolve_rev (repo, collection_ref.collection_id,
|
||||
state->remote_name, ref, TRUE, &rev,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
if (!flatpak_repo_resolve_rev (repo, collection_ref.collection_id,
|
||||
state->remote_name, ref, TRUE, &rev,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
#else
|
||||
gsize i;
|
||||
for (i = 0, rev = NULL; results[i] != NULL && rev == NULL; i++)
|
||||
|
||||
@@ -1004,6 +1004,7 @@ flatpak_installation_list_installed_refs_for_update (FlatpakInstallation *self,
|
||||
g_auto(OstreeRepoFinderResultv) results = NULL;
|
||||
g_autoptr(GAsyncResult) result = NULL;
|
||||
g_autoptr(GPtrArray) collection_refs = NULL; /* (element-type OstreeCollectionRef) */
|
||||
g_autoptr(GString) refs_str = NULL;
|
||||
|
||||
remote_commits = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
@@ -1078,6 +1079,7 @@ flatpak_installation_list_installed_refs_for_update (FlatpakInstallation *self,
|
||||
|
||||
collection_refs = g_ptr_array_new ();
|
||||
|
||||
refs_str = g_string_new ("");
|
||||
for (i = 0; i < installed->len; i++)
|
||||
{
|
||||
FlatpakInstalledRef *installed_ref = g_ptr_array_index (installed, i);
|
||||
@@ -1090,6 +1092,10 @@ flatpak_installation_list_installed_refs_for_update (FlatpakInstallation *self,
|
||||
g_autofree char *ref = flatpak_ref_format_ref (FLATPAK_REF (installed_ref));
|
||||
OstreeCollectionRef *c_r = ostree_collection_ref_new (collection_id, ref);
|
||||
g_ptr_array_add (collection_refs, c_r);
|
||||
|
||||
if (i != 0)
|
||||
g_string_append (refs_str, ", ");
|
||||
g_string_append_printf (refs_str, "(%s, %s)", collection_id, ref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,6 +1127,12 @@ flatpak_installation_list_installed_refs_for_update (FlatpakInstallation *self,
|
||||
|
||||
if (results == NULL)
|
||||
return NULL;
|
||||
|
||||
if (results[0] == NULL)
|
||||
{
|
||||
flatpak_fail (error, _("No remotes found which provide these refs: [%s]"), refs_str->str);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < installed->len; i++)
|
||||
@@ -1277,7 +1289,10 @@ list_remotes_for_configured_remote (FlatpakInstallation *self,
|
||||
if (types_filter[FLATPAK_REMOTE_TYPE_LAN])
|
||||
ostree_repo_finder_avahi_stop (OSTREE_REPO_FINDER_AVAHI (finder_avahi));
|
||||
|
||||
for (i = 0; results != NULL && results[i] != NULL; i++)
|
||||
if (results == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; results[i] != NULL; i++)
|
||||
{
|
||||
g_ptr_array_add (remotes,
|
||||
flatpak_remote_new_from_ostree (results[i]->remote,
|
||||
|
||||
Reference in New Issue
Block a user