From aed8a6b09aecd5b71536148bae83bb29661c209c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 7 Jun 2017 13:42:15 -0400 Subject: [PATCH] lib/commit: Port final object writing function to new code style I noticed my previous patches incorrectly started doing `return glnx_throw*` inside a `goto out;` function. Fix this by porting forward consistently to new style. We just do the error prefixing in the caller. Closes: #914 Approved by: alexlarsson --- src/libostree/ostree-repo-commit.c | 76 +++++++++--------------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index be92a627..27d080ad 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -193,8 +193,6 @@ commit_loose_object_trusted (OstreeRepo *self, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; - /* We may be writing as root to a non-root-owned repository; if so, * automatically inherit the non-root ownership. */ @@ -204,19 +202,13 @@ commit_loose_object_trusted (OstreeRepo *self, if (fd != -1) { if (fchown (fd, self->target_owner_uid, self->target_owner_gid) < 0) - { - glnx_set_error_from_errno (error); - goto out; - } + return glnx_throw_errno_prefix (error, "fchown"); } else if (G_UNLIKELY (fchownat (self->tmp_dir_fd, temp_filename, self->target_owner_uid, self->target_owner_gid, AT_SYMLINK_NOFOLLOW) == -1)) - { - glnx_set_error_from_errno (error); - goto out; - } + return glnx_throw_errno_prefix (error, "fchownat"); } /* Special handling for symlinks in bare repositories */ @@ -235,48 +227,31 @@ commit_loose_object_trusted (OstreeRepo *self, if (G_UNLIKELY (fchownat (self->tmp_dir_fd, temp_filename, uid, gid, AT_SYMLINK_NOFOLLOW) == -1)) - { - glnx_set_error_from_errno (error); - goto out; - } + return glnx_throw_errno_prefix (error, "fchownat"); if (xattrs != NULL) { ot_security_smack_reset_dfd_name (self->tmp_dir_fd, temp_filename); if (!glnx_dfd_name_set_all_xattrs (self->tmp_dir_fd, temp_filename, xattrs, cancellable, error)) - goto out; + return FALSE; } } else { - int res; - if (objtype == OSTREE_OBJECT_TYPE_FILE && self->mode == OSTREE_REPO_MODE_BARE) { - do - res = fchown (fd, uid, gid); - while (G_UNLIKELY (res == -1 && errno == EINTR)); - if (G_UNLIKELY (res == -1)) - { - glnx_set_error_from_errno (error); - goto out; - } + if (TEMP_FAILURE_RETRY (fchown (fd, uid, gid)) < 0) + return glnx_throw_errno_prefix (error, "fchown"); - do - res = fchmod (fd, mode); - while (G_UNLIKELY (res == -1 && errno == EINTR)); - if (G_UNLIKELY (res == -1)) - { - glnx_set_error_from_errno (error); - goto out; - } + if (TEMP_FAILURE_RETRY (fchmod (fd, mode)) < 0) + return glnx_throw_errno_prefix (error, "fchmod"); if (xattrs) { ot_security_smack_reset_fd (fd); if (!glnx_fd_set_all_xattrs (fd, xattrs, cancellable, error)) - goto out; + return FALSE; } } @@ -317,14 +292,8 @@ commit_loose_object_trusted (OstreeRepo *self, * set the modification time to OSTREE_TIMESTAMP. */ const struct timespec times[2] = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0} }; - do - res = futimens (fd, times); - while (G_UNLIKELY (res == -1 && errno == EINTR)); - if (G_UNLIKELY (res == -1)) - { - glnx_set_error_from_errno (error); - goto out; - } + if (TEMP_FAILURE_RETRY (futimens (fd, times)) < 0) + return glnx_throw_errno_prefix (error, "futimens"); } /* Ensure that in case of a power cut, these files have the data we @@ -333,23 +302,16 @@ commit_loose_object_trusted (OstreeRepo *self, if (!self->in_transaction && !self->disable_fsync) { if (fsync (fd) == -1) - { - glnx_set_error_from_errno (error); - goto out; - } + return glnx_throw_errno_prefix (error, "fsync"); } } if (!_ostree_repo_commit_loose_final (self, checksum, objtype, self->tmp_dir_fd, fd, temp_filename, cancellable, error)) - goto out; - - ret = TRUE; - out: - if (G_UNLIKELY (error && *error)) - g_prefix_error (error, "Writing object %s.%s: ", checksum, ostree_object_type_to_string (objtype)); - return ret; + return FALSE; + + return TRUE; } typedef struct @@ -551,7 +513,10 @@ _ostree_repo_commit_trusted_content_bare (OstreeRepo *self, FALSE, uid, gid, mode, xattrs, state->fd, cancellable, error)) - goto out; + { + g_prefix_error (error, "Writing object %s.%s: ", checksum, ostree_object_type_to_string (OSTREE_OBJECT_TYPE_FILE)); + goto out; + } } ret = TRUE; @@ -798,7 +763,8 @@ write_content_object (OstreeRepo *self, uid, gid, mode, xattrs, temp_fd, cancellable, error)) - return FALSE; + return glnx_prefix_error (error, "Writing object %s.%s: ", actual_checksum, + ostree_object_type_to_string (OSTREE_OBJECT_TYPE_FILE)); /* Clear the unlinker path, it was consumed */ tmp_unlinker.path = NULL;