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
This commit is contained in:
Colin Walters 2017-06-07 13:42:15 -04:00 committed by Atomic Bot
parent 5de201df26
commit aed8a6b09a
1 changed files with 21 additions and 55 deletions

View File

@ -193,8 +193,6 @@ commit_loose_object_trusted (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
/* We may be writing as root to a non-root-owned repository; if so, /* We may be writing as root to a non-root-owned repository; if so,
* automatically inherit the non-root ownership. * automatically inherit the non-root ownership.
*/ */
@ -204,19 +202,13 @@ commit_loose_object_trusted (OstreeRepo *self,
if (fd != -1) if (fd != -1)
{ {
if (fchown (fd, self->target_owner_uid, self->target_owner_gid) < 0) if (fchown (fd, self->target_owner_uid, self->target_owner_gid) < 0)
{ return glnx_throw_errno_prefix (error, "fchown");
glnx_set_error_from_errno (error);
goto out;
}
} }
else if (G_UNLIKELY (fchownat (self->tmp_dir_fd, temp_filename, else if (G_UNLIKELY (fchownat (self->tmp_dir_fd, temp_filename,
self->target_owner_uid, self->target_owner_uid,
self->target_owner_gid, self->target_owner_gid,
AT_SYMLINK_NOFOLLOW) == -1)) AT_SYMLINK_NOFOLLOW) == -1))
{ return glnx_throw_errno_prefix (error, "fchownat");
glnx_set_error_from_errno (error);
goto out;
}
} }
/* Special handling for symlinks in bare repositories */ /* 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, if (G_UNLIKELY (fchownat (self->tmp_dir_fd, temp_filename,
uid, gid, uid, gid,
AT_SYMLINK_NOFOLLOW) == -1)) AT_SYMLINK_NOFOLLOW) == -1))
{ return glnx_throw_errno_prefix (error, "fchownat");
glnx_set_error_from_errno (error);
goto out;
}
if (xattrs != NULL) if (xattrs != NULL)
{ {
ot_security_smack_reset_dfd_name (self->tmp_dir_fd, temp_filename); 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, if (!glnx_dfd_name_set_all_xattrs (self->tmp_dir_fd, temp_filename,
xattrs, cancellable, error)) xattrs, cancellable, error))
goto out; return FALSE;
} }
} }
else else
{ {
int res;
if (objtype == OSTREE_OBJECT_TYPE_FILE && self->mode == OSTREE_REPO_MODE_BARE) if (objtype == OSTREE_OBJECT_TYPE_FILE && self->mode == OSTREE_REPO_MODE_BARE)
{ {
do if (TEMP_FAILURE_RETRY (fchown (fd, uid, gid)) < 0)
res = fchown (fd, uid, gid); return glnx_throw_errno_prefix (error, "fchown");
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1))
{
glnx_set_error_from_errno (error);
goto out;
}
do if (TEMP_FAILURE_RETRY (fchmod (fd, mode)) < 0)
res = fchmod (fd, mode); return glnx_throw_errno_prefix (error, "fchmod");
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1))
{
glnx_set_error_from_errno (error);
goto out;
}
if (xattrs) if (xattrs)
{ {
ot_security_smack_reset_fd (fd); ot_security_smack_reset_fd (fd);
if (!glnx_fd_set_all_xattrs (fd, xattrs, cancellable, error)) 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. * set the modification time to OSTREE_TIMESTAMP.
*/ */
const struct timespec times[2] = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0} }; const struct timespec times[2] = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0} };
do if (TEMP_FAILURE_RETRY (futimens (fd, times)) < 0)
res = futimens (fd, times); return glnx_throw_errno_prefix (error, "futimens");
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (G_UNLIKELY (res == -1))
{
glnx_set_error_from_errno (error);
goto out;
}
} }
/* Ensure that in case of a power cut, these files have the data we /* 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 (!self->in_transaction && !self->disable_fsync)
{ {
if (fsync (fd) == -1) if (fsync (fd) == -1)
{ return glnx_throw_errno_prefix (error, "fsync");
glnx_set_error_from_errno (error);
goto out;
}
} }
} }
if (!_ostree_repo_commit_loose_final (self, checksum, objtype, if (!_ostree_repo_commit_loose_final (self, checksum, objtype,
self->tmp_dir_fd, fd, temp_filename, self->tmp_dir_fd, fd, temp_filename,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
if (G_UNLIKELY (error && *error))
g_prefix_error (error, "Writing object %s.%s: ", checksum, ostree_object_type_to_string (objtype));
return ret;
} }
typedef struct typedef struct
@ -551,7 +513,10 @@ _ostree_repo_commit_trusted_content_bare (OstreeRepo *self,
FALSE, uid, gid, mode, FALSE, uid, gid, mode,
xattrs, state->fd, xattrs, state->fd,
cancellable, error)) 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; ret = TRUE;
@ -798,7 +763,8 @@ write_content_object (OstreeRepo *self,
uid, gid, mode, uid, gid, mode,
xattrs, temp_fd, xattrs, temp_fd,
cancellable, error)) 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 */ /* Clear the unlinker path, it was consumed */
tmp_unlinker.path = NULL; tmp_unlinker.path = NULL;