mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-09-12 08:49:34 -04:00
fuse-overlayfs: propagate errors from readdir(3)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
cc18f5ce18
commit
d55cd97b73
86
main.c
86
main.c
@ -786,13 +786,28 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (((dent = readdir (dp)) != NULL))
|
for (;;)
|
||||||
{
|
{
|
||||||
struct ovl_node key;
|
struct ovl_node key;
|
||||||
const char *wh;
|
const char *wh;
|
||||||
struct ovl_node *child = NULL;
|
struct ovl_node *child = NULL;
|
||||||
char node_path[PATH_MAX + 1];
|
char node_path[PATH_MAX + 1];
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
dent = readdir (dp);
|
||||||
|
if (dent == NULL)
|
||||||
|
{
|
||||||
|
if (errno)
|
||||||
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
|
closedir (dp);
|
||||||
|
errno = saved_errno;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
key.name = dent->d_name;
|
key.name = dent->d_name;
|
||||||
|
|
||||||
if ((strcmp (dent->d_name, ".") == 0) || strcmp (dent->d_name, "..") == 0)
|
if ((strcmp (dent->d_name, ".") == 0) || strcmp (dent->d_name, "..") == 0)
|
||||||
@ -1163,15 +1178,35 @@ create_missing_whiteouts (struct ovl_data *lo, struct ovl_node *node, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
dp = fdopendir (fd);
|
dp = fdopendir (fd);
|
||||||
if (dp)
|
if (dp == NULL)
|
||||||
|
{
|
||||||
|
close (fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
|
||||||
while (dp && ((dent = readdir (dp)) != NULL))
|
for (;;)
|
||||||
{
|
{
|
||||||
struct ovl_node key;
|
struct ovl_node key;
|
||||||
struct ovl_node *n;
|
struct ovl_node *n;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
dent = readdir (dp);
|
||||||
|
if (dent == NULL)
|
||||||
|
{
|
||||||
|
if (errno)
|
||||||
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
|
closedir (dp);
|
||||||
|
errno = saved_errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp (dent->d_name, ".") == 0)
|
if (strcmp (dent->d_name, ".") == 0)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp (dent->d_name, "..") == 0)
|
if (strcmp (dent->d_name, "..") == 0)
|
||||||
@ -1777,28 +1812,45 @@ empty_dir (struct ovl_data *lo, struct ovl_node *node)
|
|||||||
{
|
{
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
int fd;
|
int fd;
|
||||||
|
struct dirent *dent;
|
||||||
|
|
||||||
fd = TEMP_FAILURE_RETRY (openat (get_upper_layer (lo)->fd, node->path, O_DIRECTORY));
|
fd = TEMP_FAILURE_RETRY (openat (get_upper_layer (lo)->fd, node->path, O_DIRECTORY));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dp = fdopendir (fd);
|
dp = fdopendir (fd);
|
||||||
if (dp)
|
if (dp == NULL)
|
||||||
{
|
{
|
||||||
struct dirent *dent;
|
close (fd);
|
||||||
|
return -1;
|
||||||
while (dp && ((dent = readdir (dp)) != NULL))
|
|
||||||
{
|
|
||||||
if (strcmp (dent->d_name, ".") == 0)
|
|
||||||
continue;
|
|
||||||
if (strcmp (dent->d_name, "..") == 0)
|
|
||||||
continue;
|
|
||||||
if (unlinkat (dirfd (dp), dent->d_name, 0) < 0)
|
|
||||||
unlinkat (dirfd (dp), dent->d_name, AT_REMOVEDIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir (dp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
errno = 0;
|
||||||
|
dent = readdir (dp);
|
||||||
|
if (dent == NULL)
|
||||||
|
{
|
||||||
|
if (errno)
|
||||||
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
|
closedir (dp);
|
||||||
|
errno = saved_errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcmp (dent->d_name, ".") == 0)
|
||||||
|
continue;
|
||||||
|
if (strcmp (dent->d_name, "..") == 0)
|
||||||
|
continue;
|
||||||
|
if (unlinkat (dirfd (dp), dent->d_name, 0) < 0)
|
||||||
|
unlinkat (dirfd (dp), dent->d_name, AT_REMOVEDIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir (dp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user