aboutsummaryrefslogtreecommitdiff
path: root/lib/dirtree.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-10-29 10:59:46 -0500
committerRob Landley <rob@landley.net>2019-10-29 10:59:46 -0500
commit0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea (patch)
treed21b945ebd5a39055903b0bb7c74d1238556195a /lib/dirtree.c
parentdba8041341d9520a1c78df81938d0dd7d3b8b008 (diff)
downloadtoybox-0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea.tar.gz
Let "find -L -type -l" find dangling symlinks.
Diffstat (limited to 'lib/dirtree.c')
-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;