aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dirtree.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index df38b257..beaafd59 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -32,12 +32,18 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags)
int len = 0, linklen = 0, statless = 0;
if (name) {
- // open code this because haven't got node to call dirtree_parentfd() on yet
- int fd = parent ? parent->dirfd : AT_FDCWD;
-
- if (fstatat(fd, name, &st,AT_SYMLINK_NOFOLLOW*!(flags&DIRTREE_SYMFOLLOW))) {
- if (flags&DIRTREE_STATLESS) statless++;
- else goto error;
+ // open code fd = because haven't got node to call dirtree_parentfd() on yet
+ int fd = parent ? parent->dirfd : AT_FDCWD,
+ sym = AT_SYMLINK_NOFOLLOW*!(flags&DIRTREE_SYMFOLLOW);
+
+ // stat dangling symlinks
+ if (fstatat(fd, name, &st, sym)) {
+ if (errno != ENOENT
+ || (!sym && fstatat(fd, name, &st, AT_SYMLINK_NOFOLLOW)))
+ {
+ if (flags&DIRTREE_STATLESS) statless++;
+ else goto error;
+ }
}
if (S_ISLNK(st.st_mode)) {
if (0>(linklen = readlinkat(fd, name, libbuf, 4095))) goto error;