Skip to content

Commit 592e50e

Browse files
committed
main: fix lookup if underlying file is a symlink
fix lookup if the underlying file is a symlink, while it is a directory on the upper layer. Closes: #337 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent dcfadc0 commit 592e50e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

main.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,9 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c
14851485
int r;
14861486

14871487
r = it->ds->file_exists (it, whiteout_path);
1488+
if (r < 0 && errno == EACCES)
1489+
break;
1490+
14881491
if (r < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG)
14891492
return NULL;
14901493

@@ -1659,8 +1662,9 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char
16591662

16601663
for (it = lo->layers; it && !stop_lookup; it = it->next)
16611664
{
1662-
int ret;
1665+
struct stat st;
16631666
DIR *dp = NULL;
1667+
int ret;
16641668

16651669
if (n->last_layer == it)
16661670
stop_lookup = true;
@@ -1672,6 +1676,17 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char
16721676
if (ret == 0)
16731677
break;
16741678

1679+
ret = it->ds->statat (it, path, &st, AT_SYMLINK_NOFOLLOW, STATX_TYPE);
1680+
if (ret < 0)
1681+
{
1682+
if (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG)
1683+
continue;
1684+
return NULL;
1685+
}
1686+
/* not a directory, stop lookup in lower layers. */
1687+
if ((st.st_mode & S_IFMT) != S_IFDIR)
1688+
break;
1689+
16751690
dp = it->ds->opendir (it, path);
16761691
if (dp == NULL)
16771692
continue;
@@ -1720,6 +1735,8 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char
17201735
strconcat3 (node_path, PATH_MAX, n->path, "/", dent->d_name);
17211736

17221737
ret = it->ds->file_exists (it, whiteout_path);
1738+
if (ret < 0 && errno == EACCES)
1739+
continue;
17231740
if (ret < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG)
17241741
{
17251742
it->ds->closedir (dp);
@@ -2020,7 +2037,7 @@ do_lookup_file (struct ovl_data *lo, fuse_ino_t parent, const char *name)
20202037
{
20212038
int saved_errno = errno;
20222039

2023-
if (errno == ENOENT || errno == ENOTDIR)
2040+
if (errno == ENOENT || errno == ENOTDIR || errno == EACCES)
20242041
{
20252042
if (node)
20262043
continue;

tests/fedora-installs.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,17 @@ test \! -e upper/a/b
251251
mknod merged/dev-foo c 10 175
252252
attr -l merged/dev-foo
253253

254-
umount merged
254+
# https://github.com/containers/fuse-overlayfs/issues/337
255+
umount -l merged
256+
257+
rm -rf lower upper workdir merged
258+
mkdir lower upper workdir merged
255259

260+
mkdir upper/foo
261+
ln -s not/existing lower/foo
262+
263+
fuse-overlayfs -o lowerdir=lower,upperdir=upper,workdir=workdir merged
264+
265+
stat merged/foo
266+
267+
umount merged

0 commit comments

Comments
 (0)