aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-12 20:26:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-12 20:26:14 +0100
commit805f2453d02e9d5cbbbd5c37c6659691e1697630 (patch)
treecdac7c3aab6a470433a3c730bf599075b5ae19bf
parent27076b823357a650b3df8e166faab471111d9160 (diff)
downloadbusybox-w32-805f2453d02e9d5cbbbd5c37c6659691e1697630.tar.gz
busybox-w32-805f2453d02e9d5cbbbd5c37c6659691e1697630.tar.bz2
busybox-w32-805f2453d02e9d5cbbbd5c37c6659691e1697630.zip
find: print/print0/prune _can_ be inverted, fix it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c207
1 files changed, 101 insertions, 106 deletions
diff --git a/findutils/find.c b/findutils/find.c
index d49adc26d..65467ae9c 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -53,10 +53,6 @@
53 * diff -u /tmp/std_find /tmp/bb_find && echo Identical 53 * diff -u /tmp/std_find /tmp/bb_find && echo Identical
54 */ 54 */
55 55
56//applet:IF_FIND(APPLET_NOEXEC(find, find, BB_DIR_USR_BIN, BB_SUID_DROP, find))
57
58//kbuild:lib-$(CONFIG_FIND) += find.o
59
60//config:config FIND 56//config:config FIND
61//config: bool "find" 57//config: bool "find"
62//config: default y 58//config: default y
@@ -230,6 +226,106 @@
230//config: help 226//config: help
231//config: Support the 'find -links' option for matching number of links. 227//config: Support the 'find -links' option for matching number of links.
232 228
229//applet:IF_FIND(APPLET_NOEXEC(find, find, BB_DIR_USR_BIN, BB_SUID_DROP, find))
230
231//kbuild:lib-$(CONFIG_FIND) += find.o
232
233//usage:#define find_trivial_usage
234//usage: "[PATH]... [OPTIONS] [ACTIONS]"
235//usage:#define find_full_usage "\n\n"
236//usage: "Search for files and perform actions on them.\n"
237//usage: "First failed action stops processing of current file.\n"
238//usage: "Defaults: PATH is current directory, action is '-print'\n"
239//usage: "\nOptions:"
240//usage: "\n -follow Follow symlinks"
241//usage: IF_FEATURE_FIND_XDEV(
242//usage: "\n -xdev Don't descend directories on other filesystems"
243//usage: )
244//usage: IF_FEATURE_FIND_MAXDEPTH(
245//usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies"
246//usage: "\n actions to command line arguments only"
247//usage: "\n -mindepth N Don't act on first N levels"
248//usage: )
249//usage: IF_FEATURE_FIND_DEPTH(
250//usage: "\n -depth Act on directory *after* traversing it"
251//usage: )
252//usage: "\n"
253//usage: "\nActions:"
254//usage: IF_FEATURE_FIND_PAREN(
255//usage: "\n ( ACTIONS ) Group actions for -o / -a"
256//usage: )
257//usage: IF_FEATURE_FIND_NOT(
258//usage: "\n ! ACT Invert ACT's success/failure"
259//usage: )
260//usage: "\n ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2"
261//usage: "\n ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2"
262//usage: "\n Note: -a has higher priority than -o"
263//usage: "\n -name PATTERN Match file name (w/o directory name) to PATTERN"
264//usage: "\n -iname PATTERN Case insensitive -name"
265//usage: IF_FEATURE_FIND_PATH(
266//usage: "\n -path PATTERN Match path to PATTERN"
267//usage: )
268//usage: IF_FEATURE_FIND_REGEX(
269//usage: "\n -regex PATTERN Match path to regex PATTERN"
270//usage: )
271//usage: IF_FEATURE_FIND_TYPE(
272//usage: "\n -type X File type is X (one of: f,d,l,b,c,...)"
273//usage: )
274//usage: IF_FEATURE_FIND_PERM(
275//usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK),"
276//usage: "\n or exactly MASK bits are set in mode bits"
277//usage: )
278//usage: IF_FEATURE_FIND_MTIME(
279//usage: "\n -mtime DAYS Modified time is greater than (+N), less than (-N),"
280//usage: "\n or exactly N days"
281//usage: )
282//usage: IF_FEATURE_FIND_MMIN(
283//usage: "\n -mmin MINS Modified time is greater than (+N), less than (-N),"
284//usage: "\n or exactly N minutes"
285//usage: )
286//usage: IF_FEATURE_FIND_NEWER(
287//usage: "\n -newer FILE Modified time is more recent than FILE's"
288//usage: )
289//usage: IF_FEATURE_FIND_INUM(
290//usage: "\n -inum N File has inode number N"
291//usage: )
292//usage: IF_FEATURE_FIND_USER(
293//usage: "\n -user NAME File is owned by user NAME (numeric user ID allowed)"
294//usage: )
295//usage: IF_FEATURE_FIND_GROUP(
296//usage: "\n -group NAME File belongs to group NAME (numeric group ID allowed)"
297//usage: )
298//usage: IF_FEATURE_FIND_SIZE(
299//usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))"
300//usage: "\n +/-N: file size is bigger/smaller than N"
301//usage: )
302//usage: IF_FEATURE_FIND_LINKS(
303//usage: "\n -links N Number of links is greater than (+N), less than (-N),"
304//usage: "\n or exactly N"
305//usage: )
306//usage: IF_FEATURE_FIND_CONTEXT(
307//usage: "\n -context CTX File has specified security context"
308//usage: )
309//usage: IF_FEATURE_FIND_PRUNE(
310//usage: "\n -prune If current file is directory, don't descend into it"
311//usage: )
312//usage: "\nIf none of the following actions is specified, -print is assumed"
313//usage: "\n -print Print file name"
314//usage: IF_FEATURE_FIND_PRINT0(
315//usage: "\n -print0 Print file name, NUL terminated"
316//usage: )
317//usage: IF_FEATURE_FIND_EXEC(
318//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
319//usage: "\n file name. Fails if CMD exits with nonzero"
320//usage: )
321//usage: IF_FEATURE_FIND_DELETE(
322//usage: "\n -delete Delete current file/directory. Turns on -depth option"
323//usage: )
324//usage:
325//usage:#define find_example_usage
326//usage: "$ find / -name passwd\n"
327//usage: "/etc/passwd\n"
328
233#include <fnmatch.h> 329#include <fnmatch.h>
234#include "libbb.h" 330#include "libbb.h"
235#if ENABLE_FEATURE_FIND_REGEX 331#if ENABLE_FEATURE_FIND_REGEX
@@ -815,20 +911,16 @@ static action*** parse_params(char **argv)
815 /* --- Tests and actions --- */ 911 /* --- Tests and actions --- */
816 else if (parm == PARM_print) { 912 else if (parm == PARM_print) {
817 G.need_print = 0; 913 G.need_print = 0;
818 /* GNU find ignores '!' here: "find ! -print" */
819 IF_FEATURE_FIND_NOT( invert_flag = 0; )
820 (void) ALLOC_ACTION(print); 914 (void) ALLOC_ACTION(print);
821 } 915 }
822#if ENABLE_FEATURE_FIND_PRINT0 916#if ENABLE_FEATURE_FIND_PRINT0
823 else if (parm == PARM_print0) { 917 else if (parm == PARM_print0) {
824 G.need_print = 0; 918 G.need_print = 0;
825 IF_FEATURE_FIND_NOT( invert_flag = 0; )
826 (void) ALLOC_ACTION(print0); 919 (void) ALLOC_ACTION(print0);
827 } 920 }
828#endif 921#endif
829#if ENABLE_FEATURE_FIND_PRUNE 922#if ENABLE_FEATURE_FIND_PRUNE
830 else if (parm == PARM_prune) { 923 else if (parm == PARM_prune) {
831 IF_FEATURE_FIND_NOT( invert_flag = 0; )
832 (void) ALLOC_ACTION(prune); 924 (void) ALLOC_ACTION(prune);
833 } 925 }
834#endif 926#endif
@@ -844,7 +936,6 @@ static action*** parse_params(char **argv)
844 int i; 936 int i;
845 action_exec *ap; 937 action_exec *ap;
846 G.need_print = 0; 938 G.need_print = 0;
847 IF_FEATURE_FIND_NOT( invert_flag = 0; )
848 ap = ALLOC_ACTION(exec); 939 ap = ALLOC_ACTION(exec);
849 ap->exec_argv = ++argv; /* first arg after -exec */ 940 ap->exec_argv = ++argv; /* first arg after -exec */
850 /*ap->exec_argc = 0; - ALLOC_ACTION did it */ 941 /*ap->exec_argc = 0; - ALLOC_ACTION did it */
@@ -1043,102 +1134,6 @@ static action*** parse_params(char **argv)
1043#undef ALLOC_ACTION 1134#undef ALLOC_ACTION
1044} 1135}
1045 1136
1046//usage:#define find_trivial_usage
1047//usage: "[PATH]... [OPTIONS] [ACTIONS]"
1048//usage:#define find_full_usage "\n\n"
1049//usage: "Search for files and perform actions on them.\n"
1050//usage: "First failed action stops processing of current file.\n"
1051//usage: "Defaults: PATH is current directory, action is '-print'\n"
1052//usage: "\nOptions:"
1053//usage: "\n -follow Follow symlinks"
1054//usage: IF_FEATURE_FIND_XDEV(
1055//usage: "\n -xdev Don't descend directories on other filesystems"
1056//usage: )
1057//usage: IF_FEATURE_FIND_MAXDEPTH(
1058//usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies"
1059//usage: "\n actions to command line arguments only"
1060//usage: "\n -mindepth N Don't act on first N levels"
1061//usage: )
1062//usage: IF_FEATURE_FIND_DEPTH(
1063//usage: "\n -depth Act on directory *after* traversing it"
1064//usage: )
1065//usage: "\n"
1066//usage: "\nActions:"
1067//usage: IF_FEATURE_FIND_PAREN(
1068//usage: "\n ( ACTIONS ) Group actions for -o / -a"
1069//usage: )
1070//usage: IF_FEATURE_FIND_NOT(
1071//usage: "\n ! ACT Invert ACT's success/failure"
1072//usage: )
1073//usage: "\n ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2"
1074//usage: "\n ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2"
1075//usage: "\n Note: -a has higher priority than -o"
1076//usage: "\n -name PATTERN Match file name (w/o directory name) to PATTERN"
1077//usage: "\n -iname PATTERN Case insensitive -name"
1078//usage: IF_FEATURE_FIND_PATH(
1079//usage: "\n -path PATTERN Match path to PATTERN"
1080//usage: )
1081//usage: IF_FEATURE_FIND_REGEX(
1082//usage: "\n -regex PATTERN Match path to regex PATTERN"
1083//usage: )
1084//usage: IF_FEATURE_FIND_TYPE(
1085//usage: "\n -type X File type is X (one of: f,d,l,b,c,...)"
1086//usage: )
1087//usage: IF_FEATURE_FIND_PERM(
1088//usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK),"
1089//usage: "\n or exactly MASK bits are set in mode bits"
1090//usage: )
1091//usage: IF_FEATURE_FIND_MTIME(
1092//usage: "\n -mtime DAYS Modified time is greater than (+N), less than (-N),"
1093//usage: "\n or exactly N days"
1094//usage: )
1095//usage: IF_FEATURE_FIND_MMIN(
1096//usage: "\n -mmin MINS Modified time is greater than (+N), less than (-N),"
1097//usage: "\n or exactly N minutes"
1098//usage: )
1099//usage: IF_FEATURE_FIND_NEWER(
1100//usage: "\n -newer FILE Modified time is more recent than FILE's"
1101//usage: )
1102//usage: IF_FEATURE_FIND_INUM(
1103//usage: "\n -inum N File has inode number N"
1104//usage: )
1105//usage: IF_FEATURE_FIND_USER(
1106//usage: "\n -user NAME File is owned by user NAME (numeric user ID allowed)"
1107//usage: )
1108//usage: IF_FEATURE_FIND_GROUP(
1109//usage: "\n -group NAME File belongs to group NAME (numeric group ID allowed)"
1110//usage: )
1111//usage: IF_FEATURE_FIND_SIZE(
1112//usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))"
1113//usage: "\n +/-N: file size is bigger/smaller than N"
1114//usage: )
1115//usage: IF_FEATURE_FIND_LINKS(
1116//usage: "\n -links N Number of links is greater than (+N), less than (-N),"
1117//usage: "\n or exactly N"
1118//usage: )
1119//usage: IF_FEATURE_FIND_CONTEXT(
1120//usage: "\n -context CTX File has specified security context"
1121//usage: )
1122//usage: IF_FEATURE_FIND_PRUNE(
1123//usage: "\n -prune If current file is directory, don't descend into it"
1124//usage: )
1125//usage: "\nIf none of the following actions is specified, -print is assumed"
1126//usage: "\n -print Print file name"
1127//usage: IF_FEATURE_FIND_PRINT0(
1128//usage: "\n -print0 Print file name, NUL terminated"
1129//usage: )
1130//usage: IF_FEATURE_FIND_EXEC(
1131//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
1132//usage: "\n file name. Fails if CMD exits with nonzero"
1133//usage: )
1134//usage: IF_FEATURE_FIND_DELETE(
1135//usage: "\n -delete Delete current file/directory. Turns on -depth option"
1136//usage: )
1137//usage:
1138//usage:#define find_example_usage
1139//usage: "$ find / -name passwd\n"
1140//usage: "/etc/passwd\n"
1141
1142int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1137int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1143int find_main(int argc UNUSED_PARAM, char **argv) 1138int find_main(int argc UNUSED_PARAM, char **argv)
1144{ 1139{
@@ -1187,7 +1182,7 @@ IF_FEATURE_FIND_DEPTH( OPT_DEPTH ,)
1187 * expression is reached. 1182 * expression is reached.
1188 * We implement: -follow, -xdev, -mindepth, -maxdepth, -depth 1183 * We implement: -follow, -xdev, -mindepth, -maxdepth, -depth
1189 */ 1184 */
1190 /* Process options, and replace then with -a */ 1185 /* Process options, and replace them with -a */
1191 /* (-a will be ignored by recursive parser later) */ 1186 /* (-a will be ignored by recursive parser later) */
1192 argp = &argv[firstopt]; 1187 argp = &argv[firstopt];
1193 while ((arg = argp[0]) != NULL) { 1188 while ((arg = argp[0]) != NULL) {