From c8ed1c7a871c0cfe5ec1e4c0b0971f1433b62992 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 8 Sep 2023 16:50:47 -0400 Subject: [PATCH] lib/pull: Fix miscounting of missing metadata If e.g. detached metadata or a parent commit is missing, we don't consider it an error but we erroneously still increment the `n_fetched_metadata` counter, causing it to be higher than it should. This will implicitly be tested by a test added in the next patch. --- src/libostree/ostree-repo-pull.c | 4 +++- tests/test-pull-localcache.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 9ec97891..d593df25 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -1069,6 +1069,7 @@ meta_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_dat g_autoptr (GError) local_error = NULL; GError **error = &local_error; gboolean free_fetch_data = TRUE; + gboolean was_enoent = FALSE; ostree_object_name_deserialize (fetch_data->object, &checksum, &objtype); checksum_obj = ostree_object_to_string (checksum, objtype); @@ -1079,6 +1080,7 @@ meta_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_dat { if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { + was_enoent = TRUE; if (fetch_data->is_detached_meta) { /* There isn't any detached metadata, just fetch the commit */ @@ -1195,7 +1197,7 @@ out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; - if (local_error == NULL) + if (local_error == NULL && !was_enoent) pull_data->n_fetched_metadata++; if (_ostree_fetcher_should_retry_request (local_error, fetch_data->n_retries_remaining--)) diff --git a/tests/test-pull-localcache.sh b/tests/test-pull-localcache.sh index a10a93ee..f4ebdd75 100755 --- a/tests/test-pull-localcache.sh +++ b/tests/test-pull-localcache.sh @@ -48,7 +48,7 @@ commit=$(${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit -b main --tree= rm -rf repo init_repo ${CMD_PREFIX} ostree --repo=repo pull --localcache-repo repo-local origin main >out.txt -assert_file_has_content out.txt '3 metadata, 1 content objects fetched (4 meta, 5 content local)' +assert_file_has_content out.txt '2 metadata, 1 content objects fetched (4 meta, 5 content local)' echo "ok pull --localcache-repo" # Check that pulling the same commit works as well -- 2.30.2