Skip to content

Commit

Permalink
Apply reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mangelajo committed Sep 19, 2022
1 parent ecd0a0f commit 25f2623
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/libostree/ostree-core-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ GFileInfo * _ostree_stbuf_to_gfileinfo (const struct stat *stbuf);
void _ostree_gfileinfo_to_stbuf (GFileInfo *file_info, struct stat *out_stbuf);
gboolean _ostree_gfileinfo_equal (GFileInfo *a, GFileInfo *b);
gboolean _ostree_stbuf_equal (struct stat *stbuf_a, struct stat *stbuf_b);
gboolean _ostree_stbuf_is_whiteout(struct stat *stbuf);
gboolean _ostree_gfileinfo_is_whiteout(GFileInfo *file_info);
GFileInfo * _ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid);

static inline void
Expand Down
21 changes: 19 additions & 2 deletions src/libostree/ostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ _ostree_stbuf_to_gfileinfo (const struct stat *stbuf)
g_file_info_set_attribute_uint32 (ret, "unix::uid", stbuf->st_uid);
g_file_info_set_attribute_uint32 (ret, "unix::gid", stbuf->st_gid);
g_file_info_set_attribute_uint32 (ret, "unix::mode", mode);
g_file_info_set_attribute_uint32 (ret, "unix::rdev", stbuf->st_rdev);

/* those aren't stored by ostree, but used by the devino cache */
g_file_info_set_attribute_uint32 (ret, "unix::device", stbuf->st_dev);
Expand Down Expand Up @@ -1816,6 +1817,22 @@ _ostree_stbuf_equal (struct stat *stbuf_a, struct stat *stbuf_b)
return TRUE;
}

/* Check if stbuf belongs to a whiteout character device */
gboolean
_ostree_stbuf_is_whiteout(struct stat *stbuf)
{
return S_ISCHR(stbuf->st_mode) && stbuf->st_rdev == 0;
}

/* Check if GFileInfo belongs to a whiteout character device */
gboolean
_ostree_gfileinfo_is_whiteout(GFileInfo *file_info)
{
struct stat stbuf;
_ostree_gfileinfo_to_stbuf(file_info, &stbuf);
return _ostree_stbuf_is_whiteout(&stbuf);
}

/* Many parts of libostree only care about mode,uid,gid - this creates
* a new GFileInfo with those fields see.
*/
Expand Down Expand Up @@ -2014,7 +2031,7 @@ file_header_parse (GVariant *metadata,
mode = GUINT32_FROM_BE (mode);
g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);

if (S_ISREG (mode) || S_ISCHR(mode))
if (S_ISREG (mode) || _ostree_gfileinfo_is_whiteout(ret_file_info))
{
;
}
Expand Down Expand Up @@ -2065,7 +2082,7 @@ zlib_file_header_parse (GVariant *metadata,
g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
g_file_info_set_size (ret_file_info, GUINT64_FROM_BE (size));

if (S_ISREG (mode) || S_ISCHR (mode))
if (S_ISREG (mode) || _ostree_gfileinfo_is_whiteout(ret_file_info))
{
;
}
Expand Down
10 changes: 5 additions & 5 deletions src/libostree/ostree-repo-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ create_file_copy_from_input_at (OstreeRepo *repo,
if (g_str_equal (checksum, actual_checksum))
return TRUE;

/* Otherwise, fall through and do the link, we should
* get EEXIST.
*/
/* Otherwise, fall through and do the link, we should
* get EEXIST.
*/
}
}
break;
Expand All @@ -401,10 +401,10 @@ create_file_copy_from_input_at (OstreeRepo *repo,
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SPECIAL)
{
guint32 file_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
g_assert(S_ISCHR(file_mode));
g_assert(_ostree_gfileinfo_is_whiteout(file_info));

if (mknodat(destination_dfd, destination_name, file_mode, (dev_t)0) < 0)
return glnx_throw_errno_prefix (error, "Creating whiteout char device");
return glnx_throw_errno_prefix (error, "Creating whiteout char device");
if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER)
{
if (xattrs != NULL &&
Expand Down
4 changes: 2 additions & 2 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ write_content_object (OstreeRepo *self,
break;
case G_FILE_TYPE_SPECIAL:
/* Only overlayfs whiteout char 0:0 files are supported for G_FILE_TYPE_SPECIAL */
if (S_ISCHR(mode))
if (_ostree_gfileinfo_is_whiteout(file_info))
{
/* For bare mode repositories where no side file metadata is stored we want to
* avoid the creation of an empty tmp file and later setup of permissions because
Expand Down Expand Up @@ -4152,7 +4152,7 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self,
}

/* For regular files and whiteout char devices we continue */
if (S_ISREG (stbuf.st_mode) || (S_ISCHR(stbuf.st_mode) && stbuf.st_rdev == 0))
if (S_ISREG (stbuf.st_mode) || _ostree_stbuf_is_whiteout(&stbuf))
;
else if (S_ISLNK (stbuf.st_mode))
{
Expand Down
2 changes: 1 addition & 1 deletion src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4475,7 +4475,7 @@ ostree_repo_load_file (OstreeRepo *self,
if (S_ISLNK (stbuf.st_mode))
g_file_info_set_symlink_target (*out_file_info, symlink_target);
else
g_assert (S_ISREG (stbuf.st_mode) || (S_ISCHR(stbuf.st_mode) && stbuf.st_rdev == 0));
g_assert (S_ISREG (stbuf.st_mode) || _ostree_stbuf_is_whiteout(&stbuf));
}

ot_transfer_out_value (out_xattrs, &ret_xattrs);
Expand Down

0 comments on commit 25f2623

Please sign in to comment.