diff options
author | Phaedrus Leeds <mwleeds@protonmail.com> | 2021-10-15 12:24:15 -0700 |
---|---|---|
committer | Phaedrus Leeds <mwleeds@protonmail.com> | 2021-10-21 11:32:05 -0700 |
commit | 6de22f0e62de3ae1cb6cc1ba986951cf31476508 (patch) | |
tree | 1cd5086256ba9f85f1f0dbed4208a05d091cb598 | |
parent | 7f3556d92ca7af1eaabeaf893eefa2d970433368 (diff) | |
download | flatpak-6de22f0e62de3ae1cb6cc1ba986951cf31476508.tar.gz |
Include extensions in listing origin remote refs
In a recent commit I changed flatpak_dir_list_remote_refs() to make main
refs (xa.main-ref) visible for noenumerate remotes (xa.noenumerate),
meaning that an origin remote created for a flatpakref file can be used
to get information about the ref from the file even before it is
installed. This commit extends that work to include extensions of the
main ref, and updates the unit test to check for this. The reasoning is
that if GNOME Software wants to show the user information about, say,
VLC from a flatpakref file before installing it, Software would want to
also show the available plugins so the user can decide if they want to
install those as well. I haven't checked if Software actually does that;
I'm only focusing on making libflatpak do the right thing.
-rw-r--r-- | common/flatpak-dir.c | 46 | ||||
-rw-r--r-- | tests/testlibrary.c | 12 |
2 files changed, 38 insertions, 20 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index a10e5951..c5b03d3e 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -14316,17 +14316,6 @@ flatpak_dir_modify_remote (FlatpakDir *self, return TRUE; } -static gboolean -remove_unless_decomposed_in_hash (gpointer key, - gpointer value, - gpointer user_data) -{ - GHashTable *table = user_data; - const FlatpakDecomposed *d = key; - - return !g_hash_table_contains (table, d); -} - gboolean flatpak_dir_list_remote_refs (FlatpakDir *self, FlatpakRemoteState *state, @@ -14348,13 +14337,15 @@ flatpak_dir_list_remote_refs (FlatpakDir *self, g_autoptr(GHashTable) decomposed_local_refs = g_hash_table_new_full ((GHashFunc)flatpak_decomposed_hash, (GEqualFunc)flatpak_decomposed_equal, (GDestroyNotify)flatpak_decomposed_unref, NULL); g_autoptr(GHashTable) local_refs = NULL; + g_autoptr(FlatpakDecomposed) decomposed_main_ref = NULL; GHashTableIter hash_iter; gpointer key; g_autofree char *refspec_prefix = g_strconcat (state->remote_name, ":.", NULL); g_autofree char *remote_main_ref = NULL; /* For noenumerate remotes, only return data for already locally - * available refs or the ref set as xa.main-ref on the remote */ + * available refs, or the ref set as xa.main-ref on the remote, or + * extensions of that main ref */ if (!ostree_repo_list_refs (self->repo, refspec_prefix, &local_refs, cancellable, error)) @@ -14377,16 +14368,31 @@ flatpak_dir_list_remote_refs (FlatpakDir *self, remote_main_ref = flatpak_dir_get_remote_main_ref (self, state->remote_name); if (remote_main_ref != NULL && *remote_main_ref != '\0') + decomposed_main_ref = flatpak_decomposed_new_from_col_ref (remote_main_ref, state->collection_id, NULL); + + /* Then we remove all remote refs not in the local refs set, not the main + * ref, and not an extension of the main ref */ + GLNX_HASH_TABLE_FOREACH_IT (*refs, it, FlatpakDecomposed *, d, void *, v) { - g_autoptr(FlatpakDecomposed) d = flatpak_decomposed_new_from_col_ref (remote_main_ref, state->collection_id, NULL); - if (d) - g_hash_table_insert (decomposed_local_refs, g_steal_pointer (&d), NULL); - } + if (g_hash_table_contains (decomposed_local_refs, d)) + continue; + + if (decomposed_main_ref != NULL) + { + g_autofree char *main_ref_id = NULL; + g_autofree char *main_ref_prefix = NULL; + + if (flatpak_decomposed_equal (decomposed_main_ref, d)) + continue; - /* Then we remove all remote refs not in the local refs set */ - g_hash_table_foreach_remove (*refs, - remove_unless_decomposed_in_hash, - decomposed_local_refs); + main_ref_id = flatpak_decomposed_dup_id (decomposed_main_ref); + main_ref_prefix = g_strconcat (main_ref_id, ".", NULL); + if (flatpak_decomposed_id_has_prefix (d, main_ref_prefix)) + continue; + } + + g_hash_table_iter_remove (&it); + } } return TRUE; diff --git a/tests/testlibrary.c b/tests/testlibrary.c index e331a7fa..ca7a1030 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -3631,6 +3631,18 @@ ready_check_origin_remote (FlatpakTransaction *transaction) g_assert_no_error (error); g_assert_nonnull (remote_ref); + /* An extension with the main ref as a prefix should also be visible */ + g_clear_object (&remote_ref); + remote_ref = flatpak_installation_fetch_remote_ref_sync (installation, + "hello-origin", + FLATPAK_REF_KIND_RUNTIME, + "org.test.Hello.Plugin.fun", + flatpak_get_default_arch (), + "v1", + NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (remote_ref); + return TRUE; } |