From a220fd3cd3f47cbed52df311a311c55bae8cb4c7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 4 Jul 2017 15:04:08 +0100 Subject: [PATCH] app/repo: Load repository metadata from ostree-metadata ref if possible Newer repositories will store metadata there, rather than in the summary file (although the summary file will still be updated where possible for backwards compatibility). Signed-off-by: Philip Withnall --- app/flatpak-builtins-repo.c | 31 +++++++++++++++++++++++++++---- common/flatpak-utils.c | 6 ++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/flatpak-builtins-repo.c b/app/flatpak-builtins-repo.c index f4691e27..a4ae5629 100644 --- a/app/flatpak-builtins-repo.c +++ b/app/flatpak-builtins-repo.c @@ -156,9 +156,9 @@ flatpak_builtin_repo (int argc, char **argv, { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) location = NULL; - g_autoptr(GVariant) summary = NULL; g_autoptr(GVariant) meta = NULL; g_autoptr(OstreeRepo) repo = NULL; + g_autofree char *ostree_metadata_checksum = NULL; context = g_option_context_new (_("LOCATION - Repository maintenance")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); @@ -174,11 +174,34 @@ flatpak_builtin_repo (int argc, char **argv, if (!ostree_repo_open (repo, cancellable, error)) return FALSE; - summary = flatpak_repo_load_summary (repo, error); - if (summary == NULL) +#ifdef FLATPAK_ENABLE_P2P + /* Try loading the metadata from the ostree-metadata branch first. If that + * fails, fall back to the summary file. */ + if (!ostree_repo_resolve_rev (repo, OSTREE_REPO_METADATA_REF, + TRUE, &ostree_metadata_checksum, error)) return FALSE; - meta = g_variant_get_child_value (summary, 1); +#endif /* FLATPAK_ENABLE_P2P */ + if (ostree_metadata_checksum != NULL) + { + g_autoptr(GVariant) commit_v = NULL; + + if (!ostree_repo_load_commit (repo, ostree_metadata_checksum, &commit_v, NULL, error)) + return FALSE; + + meta = g_variant_get_child_value (commit_v, 0); + } + else + { + g_autoptr(GVariant) summary = NULL; + + summary = flatpak_repo_load_summary (repo, error); + if (summary == NULL) + return FALSE; + meta = g_variant_get_child_value (summary, 1); + } + + /* Print out the metadata. */ if (opt_info) print_info (meta); diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index e49c990d..7e043a65 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -3226,6 +3226,12 @@ flatpak_repo_update (OstreeRepo *repo, rev_data->metadata_contents); } + /* Note: xa.cache doesn’t need to support collection IDs for the refs listed + * in it, because the xa.cache metadata is stored on the ostree-metadata ref, + * which is itself strongly bound to a collection ID — so that collection ID + * is bound to all the refs in xa.cache. If a client is using the xa.cache + * data from a summary file (rather than an ostree-metadata branch), they are + * too old to care about collection IDs anyway. */ g_variant_builder_add (&builder, "{sv}", "xa.cache", g_variant_new_variant (g_variant_builder_end (&ref_data_builder)));