lib/commit: Drop some conditionals/clarify code in content path

Both callers of `commit_loose_object_trusted()` were passing
`OSTREE_OBJECT_TYPE_FILE`, so drop that parameter.  This in turn
allows us to drop lots of checking of that inside the function.

Add a doc comment, and rename to `commit_loose_content_object()` for clarity.

Closes: #914
Approved by: alexlarsson
This commit is contained in:
Colin Walters 2017-06-07 13:56:47 -04:00 committed by Atomic Bot
parent aed8a6b09a
commit 18ae8e5267

View File

@ -179,10 +179,13 @@ _ostree_repo_commit_loose_final (OstreeRepo *self,
return TRUE; return TRUE;
} }
/* Given either a file or symlink, apply the final metadata to it depending on
* the repository mode. Note that @checksum is assumed to have been validated by
* the caller.
*/
static gboolean static gboolean
commit_loose_object_trusted (OstreeRepo *self, commit_loose_content_object (OstreeRepo *self,
const char *checksum, const char *checksum,
OstreeObjectType objtype,
const char *temp_filename, const char *temp_filename,
gboolean object_is_symlink, gboolean object_is_symlink,
guint32 uid, guint32 uid,
@ -239,7 +242,7 @@ commit_loose_object_trusted (OstreeRepo *self,
} }
else else
{ {
if (objtype == OSTREE_OBJECT_TYPE_FILE && self->mode == OSTREE_REPO_MODE_BARE) if (self->mode == OSTREE_REPO_MODE_BARE)
{ {
if (TEMP_FAILURE_RETRY (fchown (fd, uid, gid)) < 0) if (TEMP_FAILURE_RETRY (fchown (fd, uid, gid)) < 0)
return glnx_throw_errno_prefix (error, "fchown"); return glnx_throw_errno_prefix (error, "fchown");
@ -254,9 +257,7 @@ commit_loose_object_trusted (OstreeRepo *self,
return FALSE; return FALSE;
} }
} }
else if (self->mode == OSTREE_REPO_MODE_BARE_USER)
if (objtype == OSTREE_OBJECT_TYPE_FILE &&
self->mode == OSTREE_REPO_MODE_BARE_USER)
{ {
if (!write_file_metadata_to_xattr (fd, uid, gid, mode, xattrs, error)) if (!write_file_metadata_to_xattr (fd, uid, gid, mode, xattrs, error))
return FALSE; return FALSE;
@ -272,8 +273,7 @@ commit_loose_object_trusted (OstreeRepo *self,
return glnx_throw_errno_prefix (error, "fchmod"); return glnx_throw_errno_prefix (error, "fchmod");
} }
} }
else if (objtype == OSTREE_OBJECT_TYPE_FILE && else if (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY
self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY
&& !object_is_symlink) && !object_is_symlink)
{ {
guint32 invalid_modebits = (mode & ~S_IFMT) & ~0775; guint32 invalid_modebits = (mode & ~S_IFMT) & ~0775;
@ -285,7 +285,7 @@ commit_loose_object_trusted (OstreeRepo *self,
return glnx_throw_errno_prefix (error, "fchmod"); return glnx_throw_errno_prefix (error, "fchmod");
} }
if (objtype == OSTREE_OBJECT_TYPE_FILE && _ostree_repo_mode_is_bare (self->mode)) if (_ostree_repo_mode_is_bare (self->mode))
{ {
/* To satisfy tools such as guile which compare mtimes /* To satisfy tools such as guile which compare mtimes
* to determine whether or not source files need to be compiled, * to determine whether or not source files need to be compiled,
@ -306,7 +306,7 @@ commit_loose_object_trusted (OstreeRepo *self,
} }
} }
if (!_ostree_repo_commit_loose_final (self, checksum, objtype, if (!_ostree_repo_commit_loose_final (self, checksum, OSTREE_OBJECT_TYPE_FILE,
self->tmp_dir_fd, fd, temp_filename, self->tmp_dir_fd, fd, temp_filename,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
@ -508,7 +508,7 @@ _ostree_repo_commit_trusted_content_bare (OstreeRepo *self,
if (state->fd != -1) if (state->fd != -1)
{ {
if (!commit_loose_object_trusted (self, checksum, OSTREE_OBJECT_TYPE_FILE, if (!commit_loose_content_object (self, checksum,
state->temp_filename, state->temp_filename,
FALSE, uid, gid, mode, FALSE, uid, gid, mode,
xattrs, state->fd, xattrs, state->fd,
@ -756,8 +756,7 @@ write_content_object (OstreeRepo *self,
const guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); const guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
const guint32 gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid"); const guint32 gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
const guint32 mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode"); const guint32 mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
if (!commit_loose_object_trusted (self, actual_checksum, if (!commit_loose_content_object (self, actual_checksum,
OSTREE_OBJECT_TYPE_FILE,
temp_filename, temp_filename,
object_is_symlink, object_is_symlink,
uid, gid, mode, uid, gid, mode,