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 <withnall@endlessm.com>
This commit is contained in:
Philip Withnall
2017-07-04 15:04:08 +01:00
committed by Alexander Larsson
parent 4cb47a2112
commit a220fd3cd3
2 changed files with 33 additions and 4 deletions

View File

@@ -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);

View File

@@ -3226,6 +3226,12 @@ flatpak_repo_update (OstreeRepo *repo,
rev_data->metadata_contents);
}
/* Note: xa.cache doesnt 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)));