From 44fb5e72a1496d42ff500926a99dbe4c6cb44da6 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Wed, 23 Oct 2019 09:28:11 -0600 Subject: [PATCH] lib/commit: Make size entries for existing objects If the object was already in the repo then the sizes metadata entry was skipped. Move the sizes entry creation after the data has been computed but before the early return for an existing object. --- src/libostree/ostree-repo-commit.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 752a01be..d995686b 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -1060,6 +1060,19 @@ write_content_object (OstreeRepo *self, g_assert (actual_checksum != NULL); /* Pacify static analysis */ + /* Update size metadata if configured and entry missing */ + if (self->generate_sizes && object_file_type == G_FILE_TYPE_REGULAR && + (self->object_sizes == NULL || + g_hash_table_lookup (self->object_sizes, actual_checksum) == NULL)) + { + struct stat stbuf; + + if (!glnx_fstat (tmpf.fd, &stbuf, error)) + return FALSE; + + repo_store_size_entry (self, actual_checksum, unpacked_size, stbuf.st_size); + } + /* See whether or not we have the object, now that we know the * checksum. */ @@ -1125,17 +1138,6 @@ write_content_object (OstreeRepo *self, } else { - /* Update size metadata if configured */ - if (self->generate_sizes && object_file_type == G_FILE_TYPE_REGULAR) - { - struct stat stbuf; - - if (!glnx_fstat (tmpf.fd, &stbuf, error)) - return FALSE; - - repo_store_size_entry (self, actual_checksum, unpacked_size, stbuf.st_size); - } - /* Check if a file with the same payload is present in the repository, and in case try to reflink it */ if (actual_payload_checksum && !_try_clone_from_payload_link (self, self, actual_payload_checksum, file_info, &tmpf, cancellable, error)) @@ -2638,8 +2640,11 @@ ostree_repo_write_content (OstreeRepo *self, { /* First, if we have an expected checksum, see if we already have this * object. This mirrors the same logic in ostree_repo_write_metadata(). + * + * If size metadata is needed, fall through to write_content_object() + * where the entries are made. */ - if (expected_checksum) + if (expected_checksum && !self->generate_sizes) { gboolean have_obj; if (!_ostree_repo_has_loose_object (self, expected_checksum,