From 37045b4b468460785926d73cc2bc4d288caaa9b3 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Wed, 23 Oct 2019 13:05:48 -0600 Subject: [PATCH] lib/commit: Only set generate_sizes for archive repos Rather than checking throughout the code, only set the boolean when appropriate. --- src/libostree/ostree-repo-commit.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 8c5d9411..8f059e11 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -345,6 +345,19 @@ content_size_cache_entry_free (gpointer entry) g_slice_free (OstreeContentSizeCacheEntry, entry); } +static void +repo_setup_generate_sizes (OstreeRepo *self, + OstreeRepoCommitModifier *modifier) +{ + if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES) + { + if (ostree_repo_get_mode (self) == OSTREE_REPO_MODE_ARCHIVE) + self->generate_sizes = TRUE; + else + g_debug ("Not generating sizes for non-archive repo"); + } +} + static void repo_store_size_entry (OstreeRepo *self, const gchar *checksum, @@ -956,7 +969,6 @@ write_content_object (OstreeRepo *self, g_auto(OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), NULL }; g_auto(GLnxTmpfile) tmpf = { 0, }; goffset unpacked_size = 0; - gboolean indexable = FALSE; /* Is it a symlink physically? */ if (phys_object_is_symlink) { @@ -982,9 +994,6 @@ write_content_object (OstreeRepo *self, g_assert (repo_mode == OSTREE_REPO_MODE_ARCHIVE); - if (self->generate_sizes) - indexable = TRUE; - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY|O_CLOEXEC, &tmpf, error)) return FALSE; @@ -1108,7 +1117,7 @@ write_content_object (OstreeRepo *self, else { /* Update size metadata if configured */ - if (indexable && object_file_type == G_FILE_TYPE_REGULAR) + if (self->generate_sizes && object_file_type == G_FILE_TYPE_REGULAR) { struct stat stbuf; @@ -3848,8 +3857,7 @@ ostree_repo_write_directory_to_mtree (OstreeRepo *self, } else { - if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES) - self->generate_sizes = TRUE; + repo_setup_generate_sizes (self, modifier); g_autoptr(GPtrArray) path = g_ptr_array_new (); if (!write_directory_to_mtree_internal (self, dir, mtree, modifier, path, @@ -3883,8 +3891,7 @@ ostree_repo_write_dfd_to_mtree (OstreeRepo *self, GCancellable *cancellable, GError **error) { - if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES) - self->generate_sizes = TRUE; + repo_setup_generate_sizes (self, modifier); g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE, &dfd_iter, error))