aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--findutils/Config.in16
-rw-r--r--findutils/find.c44
-rw-r--r--include/usage.h4
3 files changed, 64 insertions, 0 deletions
diff --git a/findutils/Config.in b/findutils/Config.in
index 09a5bb3cb..a32e98922 100644
--- a/findutils/Config.in
+++ b/findutils/Config.in
@@ -135,6 +135,22 @@ config FEATURE_FIND_PRUNE
135 If the file is a directory, dont descend into it. Useful for 135 If the file is a directory, dont descend into it. Useful for
136 exclusion .svn and CVS directories. 136 exclusion .svn and CVS directories.
137 137
138config FEATURE_FIND_DELETE
139 bool "Enable -delete option allowing to delete files"
140 default n
141 depends on FIND && FEATURE_FIND_DEPTH
142 help
143 Support the 'find -delete' option for deleting files and direcotries.
144 WARNING: This option can do much harm if used wrong. Busybox will not
145 try to protect the user from doing stupid things. Use with care.
146
147config FEATURE_FIND_PATH
148 bool "Enable -path option allowing to match pathname patterns"
149 default y
150 depends on FIND
151 help
152 The -path option matches whole pathnames instead of just filenames.
153
138config GREP 154config GREP
139 bool "grep" 155 bool "grep"
140 default n 156 default n
diff --git a/findutils/find.c b/findutils/find.c
index b77d36dc3..aec22a5bc 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -79,6 +79,8 @@ USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
79USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) 79USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
80USE_FEATURE_FIND_SIZE( ACTS(size, off_t size;)) 80USE_FEATURE_FIND_SIZE( ACTS(size, off_t size;))
81USE_FEATURE_FIND_PRUNE( ACTS(prune)) 81USE_FEATURE_FIND_PRUNE( ACTS(prune))
82USE_FEATURE_FIND_DELETE(ACTS(delete))
83USE_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
82 84
83static action ***actions; 85static action ***actions;
84static bool need_print = 1; 86static bool need_print = 1;
@@ -305,6 +307,28 @@ ACTF(prune)
305} 307}
306#endif 308#endif
307 309
310#if ENABLE_FEATURE_FIND_DELETE
311ACTF(delete)
312{
313 int rc;
314 if (S_ISDIR(statbuf->st_mode)) {
315 rc = rmdir(fileName);
316 } else {
317 rc = unlink(fileName);
318 }
319 if (rc < 0)
320 bb_perror_msg("%s", fileName);
321 return TRUE;
322}
323#endif
324
325#if ENABLE_FEATURE_FIND_PATH
326ACTF(path)
327{
328 return fnmatch(ap->pattern, fileName, 0) == 0;
329}
330#endif
331
308#if ENABLE_FEATURE_FIND_SIZE 332#if ENABLE_FEATURE_FIND_SIZE
309ACTF(size) 333ACTF(size)
310{ 334{
@@ -393,6 +417,8 @@ static action*** parse_params(char **argv)
393 USE_FEATURE_FIND_PAREN( PARM_char_brace,) 417 USE_FEATURE_FIND_PAREN( PARM_char_brace,)
394 USE_FEATURE_FIND_SIZE( PARM_size ,) 418 USE_FEATURE_FIND_SIZE( PARM_size ,)
395 USE_FEATURE_FIND_PRUNE( PARM_prune ,) 419 USE_FEATURE_FIND_PRUNE( PARM_prune ,)
420 USE_FEATURE_FIND_DELETE(PARM_delete ,)
421 USE_FEATURE_FIND_PATH( PARM_path ,)
396#if ENABLE_DESKTOP 422#if ENABLE_DESKTOP
397 PARM_and , 423 PARM_and ,
398 PARM_or , 424 PARM_or ,
@@ -420,6 +446,8 @@ static action*** parse_params(char **argv)
420 USE_FEATURE_FIND_PAREN( "(" ,) 446 USE_FEATURE_FIND_PAREN( "(" ,)
421 USE_FEATURE_FIND_SIZE( "-size" ,) 447 USE_FEATURE_FIND_SIZE( "-size" ,)
422 USE_FEATURE_FIND_PRUNE( "-prune" ,) 448 USE_FEATURE_FIND_PRUNE( "-prune" ,)
449 USE_FEATURE_FIND_DELETE("-delete",)
450 USE_FEATURE_FIND_PATH( "-path" ,)
423#if ENABLE_DESKTOP 451#if ENABLE_DESKTOP
424 "-and" , 452 "-and" ,
425 "-or" , 453 "-or" ,
@@ -656,6 +684,22 @@ static action*** parse_params(char **argv)
656 (void) ALLOC_ACTION(prune); 684 (void) ALLOC_ACTION(prune);
657 } 685 }
658#endif 686#endif
687#if ENABLE_FEATURE_FIND_DELETE
688 else if (parm == PARM_delete) {
689 need_print = 0;
690 recurse_flags |= ACTION_DEPTHFIRST;
691 (void) ALLOC_ACTION(delete);
692 }
693#endif
694#if ENABLE_FEATURE_FIND_PATH
695 else if (parm == PARM_path) {
696 action_path *ap;
697 if (!*++argv)
698 bb_error_msg_and_die(bb_msg_requires_arg, arg);
699 ap = ALLOC_ACTION(path);
700 ap->pattern = arg1;
701 }
702#endif
659#if ENABLE_FEATURE_FIND_SIZE 703#if ENABLE_FEATURE_FIND_SIZE
660 else if (parm == PARM_size) { 704 else if (parm == PARM_size) {
661 action_size *ap; 705 action_size *ap;
diff --git a/include/usage.h b/include/usage.h
index d196afcbf..2fb8112b0 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -968,6 +968,10 @@
968 "\n -size N File size is N" \ 968 "\n -size N File size is N" \
969 ) USE_FEATURE_FIND_PRUNE( \ 969 ) USE_FEATURE_FIND_PRUNE( \
970 "\n -prune Stop traversing current subtree" \ 970 "\n -prune Stop traversing current subtree" \
971 ) USE_FEATURE_FIND_DELETE( \
972 "\n -delete Delete files; Turns on -depth option" \
973 ) USE_FEATURE_FIND_PATH( \
974 "\n -path Path matches PATTERN" \
971 ) USE_FEATURE_FIND_PAREN( \ 975 ) USE_FEATURE_FIND_PAREN( \
972 "\n (EXPR) Group an expression" \ 976 "\n (EXPR) Group an expression" \
973 ) 977 )