Skip to content

Commit

Permalink
lib/commit: Drop some conditionals/clarify code in content path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Jun 12, 2017
1 parent aed8a6b commit 18ae8e5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ _ostree_repo_commit_loose_final (OstreeRepo *self,
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
commit_loose_object_trusted (OstreeRepo *self,
commit_loose_content_object (OstreeRepo *self,
const char *checksum,
OstreeObjectType objtype,
const char *temp_filename,
gboolean object_is_symlink,
guint32 uid,
Expand Down Expand Up @@ -239,7 +242,7 @@ commit_loose_object_trusted (OstreeRepo *self,
}
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)
return glnx_throw_errno_prefix (error, "fchown");
Expand All @@ -254,9 +257,7 @@ commit_loose_object_trusted (OstreeRepo *self,
return FALSE;
}
}

if (objtype == OSTREE_OBJECT_TYPE_FILE &&
self->mode == OSTREE_REPO_MODE_BARE_USER)
else if (self->mode == OSTREE_REPO_MODE_BARE_USER)
{
if (!write_file_metadata_to_xattr (fd, uid, gid, mode, xattrs, error))
return FALSE;
Expand All @@ -272,8 +273,7 @@ commit_loose_object_trusted (OstreeRepo *self,
return glnx_throw_errno_prefix (error, "fchmod");
}
}
else if (objtype == OSTREE_OBJECT_TYPE_FILE &&
self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY
else if (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY
&& !object_is_symlink)
{
guint32 invalid_modebits = (mode & ~S_IFMT) & ~0775;
Expand All @@ -285,7 +285,7 @@ commit_loose_object_trusted (OstreeRepo *self,
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 determine whether or not source files need to be compiled,
Expand All @@ -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,
cancellable, error))
return FALSE;
Expand Down Expand Up @@ -508,7 +508,7 @@ _ostree_repo_commit_trusted_content_bare (OstreeRepo *self,

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,
FALSE, uid, gid, mode,
xattrs, state->fd,
Expand Down Expand Up @@ -756,8 +756,7 @@ write_content_object (OstreeRepo *self,
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 mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
if (!commit_loose_object_trusted (self, actual_checksum,
OSTREE_OBJECT_TYPE_FILE,
if (!commit_loose_content_object (self, actual_checksum,
temp_filename,
object_is_symlink,
uid, gid, mode,
Expand Down

0 comments on commit 18ae8e5

Please sign in to comment.