From f97f4e72e9ead6dcd0f747d5c780c0878b873e7f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 28 Aug 2019 14:37:50 -0700 Subject: Fix find(1) after c26870dab346. Unlike ls, find does treat ENOENT specially. Add an extra test (and fix the behavior) for the case of ENOENT for a path provided on the command line --- unlike other ENOENT cases (typically dangling symlinks), ENOENT for a command line argument should report an error. Also remove obsolete `|sed` from the symlink loop test. --- toys/posix/find.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'toys/posix/find.c') diff --git a/toys/posix/find.c b/toys/posix/find.c index 782cc3bc..58a6f88d 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -216,6 +216,14 @@ static int do_find(struct dirtree *new) // skip . and .. below topdir, handle -xdev and -depth if (new) { + // Handle stat failures first. + if (!new->st.st_blksize && !new->st.st_dev && !new->st.st_ino) { + if (!new->parent || errno != ENOENT) { + perror_msg("'%s'", s = dirtree_path(new, 0)); + free(s); + } + return 0; + } if (new->parent) { if (!dirtree_notdotdot(new)) return 0; if (TT.xdev && new->st.st_dev != new->parent->st.st_dev) recurse = 0; -- cgit v1.2.3