fuse-overlayfs: attempt to delete node whiteout first

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2018-07-12 14:49:04 +02:00
parent 4d34e45e37
commit 9c5acf4bf2
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

26
main.c
View File

@ -318,8 +318,34 @@ create_whiteout (struct ovl_data *lo, struct ovl_node *parent, const char *name)
static int
delete_whiteout (struct ovl_data *lo, int dirfd, struct ovl_node *parent, const char *name)
{
struct stat st;
char whiteout_path[PATH_MAX + 10];
if (dirfd >= 0)
{
if (TEMP_FAILURE_RETRY (fstatat (dirfd, name, &st, AT_SYMLINK_NOFOLLOW)) == 0
&& (st.st_mode & S_IFMT) == S_IFCHR
&& major (st.st_rdev) == 0
&& minor (st.st_rdev) == 0)
{
return unlinkat (dirfd, name, 0);
}
}
else
{
sprintf (whiteout_path, "%s/.wh.%s", parent->path, name);
if (TEMP_FAILURE_RETRY (fstatat (get_upper_layer (lo)->fd, whiteout_path, &st, AT_SYMLINK_NOFOLLOW)) == 0
&& (st.st_mode & S_IFMT) == S_IFCHR
&& major (st.st_rdev) == 0
&& minor (st.st_rdev) == 0)
{
return unlinkat (get_upper_layer (lo)->fd, whiteout_path, 0);
}
}
/* If the whiteout was not found, try the .wh. alternative used when running as non-root. */
if (dirfd >= 0)
{
sprintf (whiteout_path, ".wh.%s", name);