Skip to content

Commit c2ff1cc

Browse files
committed
Apply reviewer comments
1 parent ecd0a0f commit c2ff1cc

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

src/libostree/ostree-core-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ GFileInfo * _ostree_stbuf_to_gfileinfo (const struct stat *stbuf);
9191
void _ostree_gfileinfo_to_stbuf (GFileInfo *file_info, struct stat *out_stbuf);
9292
gboolean _ostree_gfileinfo_equal (GFileInfo *a, GFileInfo *b);
9393
gboolean _ostree_stbuf_equal (struct stat *stbuf_a, struct stat *stbuf_b);
94+
gboolean _ostree_stbuf_is_whiteout(struct stat *stbuf);
95+
gboolean _ostree_gfileinfo_is_whiteout(GFileInfo *file_info);
9496
GFileInfo * _ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid);
9597

9698
static inline void

src/libostree/ostree-core.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ _ostree_stbuf_to_gfileinfo (const struct stat *stbuf)
17321732
g_file_info_set_attribute_uint32 (ret, "unix::uid", stbuf->st_uid);
17331733
g_file_info_set_attribute_uint32 (ret, "unix::gid", stbuf->st_gid);
17341734
g_file_info_set_attribute_uint32 (ret, "unix::mode", mode);
1735+
g_file_info_set_attribute_uint32 (ret, "unix::rdev", stbuf->st_rdev);
17351736

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

1820+
/* Check if stbuf belongs to a whiteout character device */
1821+
gboolean
1822+
_ostree_stbuf_is_whiteout(struct stat *stbuf)
1823+
{
1824+
return S_ISCHR(stbuf->st_mode) && stbuf->st_rdev == 0;
1825+
}
1826+
1827+
/* Check if GFileInfo belongs to a whiteout character device */
1828+
gboolean
1829+
_ostree_gfileinfo_is_whiteout(GFileInfo *file_info)
1830+
{
1831+
struct stat stbuf;
1832+
_ostree_gfileinfo_to_stbuf(file_info, &stbuf);
1833+
return _ostree_stbuf_is_whiteout(&stbuf);
1834+
}
1835+
18191836
/* Many parts of libostree only care about mode,uid,gid - this creates
18201837
* a new GFileInfo with those fields see.
18211838
*/
@@ -2014,7 +2031,7 @@ file_header_parse (GVariant *metadata,
20142031
mode = GUINT32_FROM_BE (mode);
20152032
g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
20162033

2017-
if (S_ISREG (mode) || S_ISCHR(mode))
2034+
if (S_ISREG (mode) || _ostree_gfileinfo_is_whiteout(ret_file_info))
20182035
{
20192036
;
20202037
}
@@ -2065,7 +2082,7 @@ zlib_file_header_parse (GVariant *metadata,
20652082
g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
20662083
g_file_info_set_size (ret_file_info, GUINT64_FROM_BE (size));
20672084

2068-
if (S_ISREG (mode) || S_ISCHR (mode))
2085+
if (S_ISREG (mode) || _ostree_gfileinfo_is_whiteout(ret_file_info))
20692086
{
20702087
;
20712088
}

src/libostree/ostree-repo-checkout.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ create_file_copy_from_input_at (OstreeRepo *repo,
385385
if (g_str_equal (checksum, actual_checksum))
386386
return TRUE;
387387

388-
/* Otherwise, fall through and do the link, we should
389-
* get EEXIST.
390-
*/
388+
/* Otherwise, fall through and do the link, we should
389+
* get EEXIST.
390+
*/
391391
}
392392
}
393393
break;
@@ -401,10 +401,10 @@ create_file_copy_from_input_at (OstreeRepo *repo,
401401
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SPECIAL)
402402
{
403403
guint32 file_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
404-
g_assert(S_ISCHR(file_mode));
404+
g_assert(_ostree_gfileinfo_is_whiteout(file_info));
405405

406406
if (mknodat(destination_dfd, destination_name, file_mode, (dev_t)0) < 0)
407-
return glnx_throw_errno_prefix (error, "Creating whiteout char device");
407+
return glnx_throw_errno_prefix (error, "Creating whiteout char device");
408408
if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER)
409409
{
410410
if (xattrs != NULL &&

src/libostree/ostree-repo-commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ write_content_object (OstreeRepo *self,
10101010
break;
10111011
case G_FILE_TYPE_SPECIAL:
10121012
/* Only overlayfs whiteout char 0:0 files are supported for G_FILE_TYPE_SPECIAL */
1013-
if (S_ISCHR(mode))
1013+
if (_ostree_gfileinfo_is_whiteout(file_info))
10141014
{
10151015
/* For bare mode repositories where no side file metadata is stored we want to
10161016
* avoid the creation of an empty tmp file and later setup of permissions because
@@ -4152,7 +4152,7 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self,
41524152
}
41534153

41544154
/* For regular files and whiteout char devices we continue */
4155-
if (S_ISREG (stbuf.st_mode) || (S_ISCHR(stbuf.st_mode) && stbuf.st_rdev == 0))
4155+
if (S_ISREG (stbuf.st_mode) || _ostree_stbuf_is_whiteout(&stbuf))
41564156
;
41574157
else if (S_ISLNK (stbuf.st_mode))
41584158
{

src/libostree/ostree-repo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,7 +4323,7 @@ _ostree_repo_load_file_bare (OstreeRepo *self,
43234323
}
43244324

43254325
if (!(S_ISREG (stbuf.st_mode) || S_ISLNK (stbuf.st_mode) ||
4326-
(S_ISCHR (stbuf.st_mode) && stbuf.st_rdev == 0)))
4326+
_ostree_stbuf_is_whiteout(&stbuf)))
43274327
return glnx_throw (error, "Not a regular file, symlink or whiteout");
43284328

43294329
/* In the non-bare-user case, gather symlink info if requested */
@@ -4475,7 +4475,7 @@ ostree_repo_load_file (OstreeRepo *self,
44754475
if (S_ISLNK (stbuf.st_mode))
44764476
g_file_info_set_symlink_target (*out_file_info, symlink_target);
44774477
else
4478-
g_assert (S_ISREG (stbuf.st_mode) || (S_ISCHR(stbuf.st_mode) && stbuf.st_rdev == 0));
4478+
g_assert (S_ISREG (stbuf.st_mode) || _ostree_stbuf_is_whiteout(&stbuf));
44794479
}
44804480

44814481
ot_transfer_out_value (out_xattrs, &ret_xattrs);

0 commit comments

Comments
 (0)