diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 0bdb70038b..45aec5e589 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -589,6 +589,31 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self, return TRUE; } +static gboolean +_create_payload_link (OstreeRepo *self, + const char *actual_checksum, + const char *actual_payload_checksum, + GFileInfo *file_info, + GCancellable *cancellable, + GError **error) +{ + if (actual_payload_checksum && g_file_info_get_size (file_info) >= self->payload_link_threshold) + { + if (symlinkat (actual_checksum, commit_tmp_dfd (self), actual_payload_checksum) < 0) + { + if (errno != EEXIST) + return glnx_throw_errno (error); + } + else + { + g_auto(OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), g_strdup (actual_payload_checksum) }; + if (!commit_path_final (self, actual_payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, &tmp_unlinker, cancellable, error)) + return FALSE; + } + } + return TRUE; +} + /* The main driver for writing a content (regfile or symlink) object. * There are a variety of tricky cases here; for example, bare-user * repos store symlinks as regular files. Computing checksums @@ -806,6 +831,10 @@ write_content_object (OstreeRepo *self, g_mutex_lock (&self->txn_lock); self->txn.stats.content_objects_total++; g_mutex_unlock (&self->txn_lock); + + if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, cancellable, error)) + return FALSE; + if (out_csum) *out_csum = ostree_checksum_to_bytes (actual_checksum); /* Note early return */ @@ -919,20 +948,8 @@ write_content_object (OstreeRepo *self, cancellable, error)) return FALSE; - if (!has_payload_object && actual_payload_checksum && g_file_info_get_size (file_info) >= self->payload_link_threshold) - { - if (symlinkat (actual_checksum, commit_tmp_dfd (self), actual_payload_checksum) < 0) - { - if (errno != EEXIST) - return glnx_throw_errno (error); - } - else - { - g_auto(OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), g_strdup (actual_payload_checksum) }; - if (!commit_path_final (self, actual_payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, &tmp_unlinker, cancellable, error)) - return FALSE; - } - } + if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, cancellable, error)) + return FALSE; } /* Update statistics */