From 2fa6e2fe973bc054c5f76ccb2a0c79e4a94ee8c8 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 11 May 2017 10:08:50 +0200 Subject: [PATCH] build-update-repo: Use the size/metadata info in the commit object If the data is already there, there is no need to re-calculate it. --- common/flatpak-utils.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index 6fe4fe0a..9d8a0555 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -3035,24 +3035,43 @@ flatpak_repo_update (OstreeRepo *repo, guint64 installed_size = 0; guint64 download_size = 0; g_autofree char *metadata_contents = NULL; + g_autofree char *commit = NULL; + g_autoptr(GVariant) commit_v = NULL; + g_autoptr(GVariant) commit_metadata = NULL; CommitData *rev_data; /* See if we already have the info on this revision */ if (g_hash_table_lookup (commit_data_cache, rev)) continue; - if (!ostree_repo_read_commit (repo, rev, &root, NULL, NULL, error)) + if (!ostree_repo_read_commit (repo, rev, &root, &commit, NULL, error)) return FALSE; - if (!flatpak_repo_collect_sizes (repo, root, &installed_size, &download_size, cancellable, error)) + if (!ostree_repo_load_commit (repo, commit, &commit_v, NULL, error)) return FALSE; + commit_metadata = g_variant_get_child_value (commit_v, 0); + if (!g_variant_lookup (commit_metadata, "xa.metadata", "s", &metadata_contents)) + { + metadata = g_file_get_child (root, "metadata"); + if (!g_file_load_contents (metadata, cancellable, &metadata_contents, NULL, NULL, NULL)) + metadata_contents = g_strdup (""); + } + + if (g_variant_lookup (commit_metadata, "xa.installed-size", "t", &installed_size) && + g_variant_lookup (commit_metadata, "xa.download-size", "t", &download_size)) + { + installed_size = GUINT64_FROM_BE (installed_size); + download_size = GUINT64_FROM_BE (download_size); + } + else + { + if (!flatpak_repo_collect_sizes (repo, root, &installed_size, &download_size, cancellable, error)) + return FALSE; + } + flatpak_repo_collect_extra_data_sizes (repo, rev, &installed_size, &download_size); - metadata = g_file_get_child (root, "metadata"); - if (!g_file_load_contents (metadata, cancellable, &metadata_contents, NULL, NULL, NULL)) - metadata_contents = g_strdup (""); - rev_data = g_new (CommitData, 1); rev_data->installed_size = installed_size; rev_data->download_size = download_size;