diff options
author | Rob Landley <rob@landley.net> | 2019-10-29 10:59:46 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-10-29 10:59:46 -0500 |
commit | 0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea (patch) | |
tree | d21b945ebd5a39055903b0bb7c74d1238556195a | |
parent | dba8041341d9520a1c78df81938d0dd7d3b8b008 (diff) | |
download | toybox-0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea.tar.gz |
Let "find -L -type -l" find dangling symlinks.
-rw-r--r-- | lib/dirtree.c | 18 |
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; |