lib/pull: Fix miscounting of missing metadata
authorJonathan Lebon <jonathan@jlebon.com>
Fri, 8 Sep 2023 20:50:47 +0000 (16:50 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Fri, 8 Sep 2023 21:49:25 +0000 (17:49 -0400)
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
tests/test-pull-localcache.sh

index 9ec9789183d3636e4ed827f7944a1f531444bc7d..d593df2523a886f19c7c669d65a3f5cf6c0280dc 100644 (file)
@@ -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--))
index a10a93eed260e6659e79d7bd48bad01e0ba2925f..f4ebdd75ae7a88077cb671479b0e77460cf11f42 100755 (executable)
@@ -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