Skip to content

Commit

Permalink
main: fix lookup if underlying file is a symlink
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
giuseppe committed Feb 1, 2022
1 parent dcfadc0 commit 592e50e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,9 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c
int r;

r = it->ds->file_exists (it, whiteout_path);
if (r < 0 && errno == EACCES)
break;

if (r < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG)
return NULL;

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

for (it = lo->layers; it && !stop_lookup; it = it->next)
{
int ret;
struct stat st;
DIR *dp = NULL;
int ret;

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

ret = it->ds->statat (it, path, &st, AT_SYMLINK_NOFOLLOW, STATX_TYPE);
if (ret < 0)
{
if (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG)
continue;
return NULL;
}
/* not a directory, stop lookup in lower layers. */
if ((st.st_mode & S_IFMT) != S_IFDIR)
break;

dp = it->ds->opendir (it, path);
if (dp == NULL)
continue;
Expand Down Expand Up @@ -1720,6 +1735,8 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char
strconcat3 (node_path, PATH_MAX, n->path, "/", dent->d_name);

ret = it->ds->file_exists (it, whiteout_path);
if (ret < 0 && errno == EACCES)
continue;
if (ret < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG)
{
it->ds->closedir (dp);
Expand Down Expand Up @@ -2020,7 +2037,7 @@ do_lookup_file (struct ovl_data *lo, fuse_ino_t parent, const char *name)
{
int saved_errno = errno;

if (errno == ENOENT || errno == ENOTDIR)
if (errno == ENOENT || errno == ENOTDIR || errno == EACCES)
{
if (node)
continue;
Expand Down
14 changes: 13 additions & 1 deletion tests/fedora-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,17 @@ test \! -e upper/a/b
mknod merged/dev-foo c 10 175
attr -l merged/dev-foo

umount merged
# https://github.com/containers/fuse-overlayfs/issues/337
umount -l merged

rm -rf lower upper workdir merged
mkdir lower upper workdir merged

mkdir upper/foo
ln -s not/existing lower/foo

fuse-overlayfs -o lowerdir=lower,upperdir=upper,workdir=workdir merged

stat merged/foo

umount merged

0 comments on commit 592e50e

Please sign in to comment.