aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-31 03:21:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-31 03:21:02 +0000
commit5f18e7ca33ad11c7114369f9799e77102bc658d9 (patch)
tree8cd37e2854d470dfd245f3227e16ab40b1fdfcca /findutils/find.c
parenta3b4fed8b3056b1a7429f809ed310512c1bd3a1e (diff)
downloadbusybox-w32-5f18e7ca33ad11c7114369f9799e77102bc658d9.tar.gz
busybox-w32-5f18e7ca33ad11c7114369f9799e77102bc658d9.tar.bz2
busybox-w32-5f18e7ca33ad11c7114369f9799e77102bc658d9.zip
find: implement -prune. "make clean" now works! :)
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 21ea9d422..bc285d36a 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -69,6 +69,7 @@ USE_FEATURE_FIND_NEWER( SACT(newer, time_t newer_mtime;))
69USE_FEATURE_FIND_INUM( SACT(inum, ino_t inode_num;)) 69USE_FEATURE_FIND_INUM( SACT(inum, ino_t inode_num;))
70USE_FEATURE_FIND_EXEC( SACT(exec, char **exec_argv; int *subst_count; int exec_argc;)) 70USE_FEATURE_FIND_EXEC( SACT(exec, char **exec_argv; int *subst_count; int exec_argc;))
71USE_DESKTOP( SACT(paren, action ***subexpr;)) 71USE_DESKTOP( SACT(paren, action ***subexpr;))
72USE_DESKTOP( SACT(prune))
72 73
73static action ***actions; 74static action ***actions;
74static int need_print = 1; 75static int need_print = 1;
@@ -224,11 +225,22 @@ SFUNC(paren)
224{ 225{
225 return exec_actions(ap->subexpr, fileName, statbuf); 226 return exec_actions(ap->subexpr, fileName, statbuf);
226} 227}
228/*
229 * -prune: if -depth is not given, return true and do not descend
230 * current dir; if -depth is given, return false with no effect.
231 * Example:
232 * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print
233 */
234SFUNC(prune)
235{
236 return SKIP;
237}
227#endif 238#endif
228 239
229 240
230static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth) 241static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth)
231{ 242{
243 int rc;
232#ifdef CONFIG_FEATURE_FIND_XDEV 244#ifdef CONFIG_FEATURE_FIND_XDEV
233 if (S_ISDIR(statbuf->st_mode) && xdev_count) { 245 if (S_ISDIR(statbuf->st_mode) && xdev_count) {
234 int i; 246 int i;
@@ -238,10 +250,13 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk, in
238 } 250 }
239 } 251 }
240#endif 252#endif
241 /* had no explicit -print[0] or -exec? then print */ 253 rc = exec_actions(actions, fileName, statbuf);
242 if (exec_actions(actions, fileName, statbuf) && need_print) 254 /* Had no explicit -print[0] or -exec? then print */
255 if (rc && need_print)
243 puts(fileName); 256 puts(fileName);
244 return TRUE; 257 /* Cannot return 0: our caller, recursive_action(),
258 * will perror() and skip dirs (if called on dir) */
259 return rc == 0 ? TRUE : rc;
245} 260}
246 261
247 262
@@ -469,6 +484,9 @@ action*** parse_params(char **argv)
469 *endarg = ")"; /* restore NULLed parameter */ 484 *endarg = ")"; /* restore NULLed parameter */
470 argv = endarg; 485 argv = endarg;
471 } 486 }
487 else if (strcmp(arg, "-prune") == 0) {
488 (void) ALLOC_ACTION(prune);
489 }
472#endif 490#endif
473 else 491 else
474 bb_show_usage(); 492 bb_show_usage();