From e3062c3bd3666d4641481dbf436c72e3d46ab727 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 26 May 2021 05:30:25 -0500 Subject: Add find -quit --- tests/find.test | 8 ++++---- toys/posix/find.c | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/find.test b/tests/find.test index f4277375..2bfa6f91 100755 --- a/tests/find.test +++ b/tests/find.test @@ -10,7 +10,7 @@ mkfifo fifo sleep .1 ln -s fifo link cd .. -touch b +touch irrelevant mkdir perm touch perm/all-read-only @@ -88,7 +88,6 @@ testing "-name FILE" "find dir -name FILE" "" "" "" testing "-iname file" "find dir -iname FILE" "dir/file\n" "" "" testing "-iname FILE" "find dir -iname FILE" "dir/file\n" "" "" - testing "-name (no arguments)" \ "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" "" testing "-iname (no arguments)" \ @@ -123,7 +122,6 @@ ln -s looper dir/looper testing "-L symlink loop noisy" \ "LANG=C find -L dir -name file 2>err ; grep -q dir/looper err || echo missing error" \ "dir/file\n" "" "" -rm -f dir/looper err testing "-false" "find dir -false" "" "" "" testing "-true" "find dir/file -true" "dir/file\n" "" "" @@ -131,6 +129,7 @@ testing "-true" "find dir/file -true" "dir/file\n" "" "" testing "missing root error" \ "LANG=C find -L dir/missing-root 2>err ; grep -q dir/missing-root err || echo missing error" \ "" "" "" +rm -f dir/looper err testing "-path match root" "find dir/f* -path dir/file" "dir/file\n" "" "" testing "-name match root" "find dir/f* -name file" "dir/file\n" "" "" @@ -143,5 +142,6 @@ testing "-L broken" "find -L broken" "broken\n" "" "" testing "one slash" 'find /etc/ -maxdepth 1 | grep /passwd\$' '/etc/passwd\n' \ '' '' testing 'empty arg' 'find "" dir -name file 2>/dev/null' 'dir/file\n' '' '' +testing 'quit' 'find dir perm -print -quit' 'dir\n' '' '' -rm -rf dir +rm -rf dir broken perm irrelevant diff --git a/toys/posix/find.c b/toys/posix/find.c index 3824f0c6..5d3f8e3e 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -37,6 +37,7 @@ config FIND -true always true -false always false -context PATTERN security context -executable access(X_OK) perm+ACL -newerXY FILE X=acm time > FILE's Y=acm time (Y=t: FILE is literal time) + -quit exit immediately Numbers N may be prefixed by a - (less than) or + (greater than). Units for -Xtime are d (days, default), h (hours), m (minutes), or s (seconds). @@ -352,6 +353,11 @@ static int do_find(struct dirtree *new) if (check && S_ISDIR(new->st.st_mode) && !TT.depth) recurse = 0; } else if (!strcmp(s, "executable")) { if (check && faccessat(dirtree_parentfd(new), new->name,X_OK,0)) test = 0; + } else if (!strcmp(s, "quit")) { + if (check) { + execdir(0, 1); + xexit(); + } // Remaining filters take an argument } else { -- cgit v1.2.3