aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
committerRon Yorston <rmy@pobox.com>2020-01-08 12:30:49 +0000
commita9271a8e97e6e7be5285330d5f19352decabf807 (patch)
treebf3c4464c369a15a46454792dac167505f74769f /findutils
parentb0b7ab792bc1f45963f4b84b94faaf05054e1613 (diff)
parent9ec836c033fc6e55e80f3309b3e05acdf09bb297 (diff)
downloadbusybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.gz
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.tar.bz2
busybox-w32-a9271a8e97e6e7be5285330d5f19352decabf807.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c44
-rw-r--r--findutils/grep.c10
2 files changed, 51 insertions, 3 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 66ad36283..121f8fd03 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -203,6 +203,14 @@
203//config: WARNING: This option can do much harm if used wrong. Busybox will not 203//config: WARNING: This option can do much harm if used wrong. Busybox will not
204//config: try to protect the user from doing stupid things. Use with care. 204//config: try to protect the user from doing stupid things. Use with care.
205//config: 205//config:
206//config:config FEATURE_FIND_EMPTY
207//config: bool "Enable -empty: match empty files or directories"
208//config: default y
209//config: depends on FIND
210//config: help
211//config: Support the 'find -empty' option to find empty regular files
212//config: or directories.
213//config:
206//config:config FEATURE_FIND_PATH 214//config:config FEATURE_FIND_PATH
207//config: bool "Enable -path: match pathname with shell pattern" 215//config: bool "Enable -path: match pathname with shell pattern"
208//config: default y 216//config: default y
@@ -315,6 +323,9 @@
315//usage: IF_FEATURE_FIND_CONTEXT( 323//usage: IF_FEATURE_FIND_CONTEXT(
316//usage: "\n -context CTX File has specified security context" 324//usage: "\n -context CTX File has specified security context"
317//usage: ) 325//usage: )
326//usage: IF_FEATURE_FIND_EMPTY(
327//usage: "\n -empty Match empty file/directory"
328//usage: )
318//usage: IF_FEATURE_FIND_PRUNE( 329//usage: IF_FEATURE_FIND_PRUNE(
319//usage: "\n -prune If current file is directory, don't descend into it" 330//usage: "\n -prune If current file is directory, don't descend into it"
320//usage: ) 331//usage: )
@@ -396,6 +407,7 @@ IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
396IF_FEATURE_FIND_PRUNE( ACTS(prune)) 407IF_FEATURE_FIND_PRUNE( ACTS(prune))
397IF_FEATURE_FIND_QUIT( ACTS(quit)) 408IF_FEATURE_FIND_QUIT( ACTS(quit))
398IF_FEATURE_FIND_DELETE( ACTS(delete)) 409IF_FEATURE_FIND_DELETE( ACTS(delete))
410IF_FEATURE_FIND_EMPTY( ACTS(empty))
399IF_FEATURE_FIND_EXEC( ACTS(exec, 411IF_FEATURE_FIND_EXEC( ACTS(exec,
400 char **exec_argv; /* -exec ARGS */ 412 char **exec_argv; /* -exec ARGS */
401 unsigned *subst_count; 413 unsigned *subst_count;
@@ -824,6 +836,30 @@ ACTF(delete)
824 return TRUE; 836 return TRUE;
825} 837}
826#endif 838#endif
839#if ENABLE_FEATURE_FIND_EMPTY
840ACTF(empty)
841{
842 if (S_ISDIR(statbuf->st_mode)) {
843 DIR *dir;
844 struct dirent *dent;
845
846 dir = opendir(fileName);
847 if (!dir) {
848 bb_simple_perror_msg(fileName);
849 return FALSE;
850 }
851
852 while ((dent = readdir(dir)) != NULL
853 && DOT_OR_DOTDOT(dent->d_name)
854 ) {
855 continue;
856 }
857 closedir(dir);
858 return dent == NULL;
859 }
860 return S_ISREG(statbuf->st_mode) && statbuf->st_size == 0;
861}
862#endif
827#if ENABLE_FEATURE_FIND_CONTEXT 863#if ENABLE_FEATURE_FIND_CONTEXT
828ACTF(context) 864ACTF(context)
829{ 865{
@@ -989,6 +1025,7 @@ static action*** parse_params(char **argv)
989 IF_FEATURE_FIND_PRUNE( PARM_prune ,) 1025 IF_FEATURE_FIND_PRUNE( PARM_prune ,)
990 IF_FEATURE_FIND_QUIT( PARM_quit ,) 1026 IF_FEATURE_FIND_QUIT( PARM_quit ,)
991 IF_FEATURE_FIND_DELETE( PARM_delete ,) 1027 IF_FEATURE_FIND_DELETE( PARM_delete ,)
1028 IF_FEATURE_FIND_EMPTY( PARM_empty ,)
992 IF_FEATURE_FIND_EXEC( PARM_exec ,) 1029 IF_FEATURE_FIND_EXEC( PARM_exec ,)
993 IF_FEATURE_FIND_EXECUTABLE(PARM_executable,) 1030 IF_FEATURE_FIND_EXECUTABLE(PARM_executable,)
994 IF_FEATURE_FIND_PAREN( PARM_char_brace,) 1031 IF_FEATURE_FIND_PAREN( PARM_char_brace,)
@@ -1034,6 +1071,7 @@ static action*** parse_params(char **argv)
1034 IF_FEATURE_FIND_PRUNE( "-prune\0" ) 1071 IF_FEATURE_FIND_PRUNE( "-prune\0" )
1035 IF_FEATURE_FIND_QUIT( "-quit\0" ) 1072 IF_FEATURE_FIND_QUIT( "-quit\0" )
1036 IF_FEATURE_FIND_DELETE( "-delete\0" ) 1073 IF_FEATURE_FIND_DELETE( "-delete\0" )
1074 IF_FEATURE_FIND_EMPTY( "-empty\0" )
1037 IF_FEATURE_FIND_EXEC( "-exec\0" ) 1075 IF_FEATURE_FIND_EXEC( "-exec\0" )
1038 IF_FEATURE_FIND_EXECUTABLE("-executable\0") 1076 IF_FEATURE_FIND_EXECUTABLE("-executable\0")
1039 IF_FEATURE_FIND_PAREN( "(\0" ) 1077 IF_FEATURE_FIND_PAREN( "(\0" )
@@ -1203,6 +1241,12 @@ static action*** parse_params(char **argv)
1203 (void) ALLOC_ACTION(delete); 1241 (void) ALLOC_ACTION(delete);
1204 } 1242 }
1205#endif 1243#endif
1244#if ENABLE_FEATURE_FIND_EMPTY
1245 else if (parm == PARM_empty) {
1246 dbg("%d", __LINE__);
1247 (void) ALLOC_ACTION(empty);
1248 }
1249#endif
1206#if ENABLE_FEATURE_FIND_EXEC 1250#if ENABLE_FEATURE_FIND_EXEC
1207 else if (parm == PARM_exec) { 1251 else if (parm == PARM_exec) {
1208 int i; 1252 int i;
diff --git a/findutils/grep.c b/findutils/grep.c
index 2cbe7ea91..5b8644c36 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -60,7 +60,7 @@
60 60
61/* options */ 61/* options */
62//usage:#define grep_trivial_usage 62//usage:#define grep_trivial_usage
63//usage: "[-HhnlLoqvsriwFE" 63//usage: "[-HhnlLoqvsrRiwFE"
64//usage: IF_EXTRA_COMPAT("z") 64//usage: IF_EXTRA_COMPAT("z")
65//usage: "] [-m N] " 65//usage: "] [-m N] "
66//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ") 66//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
@@ -78,6 +78,7 @@
78//usage: "\n -v Select non-matching lines" 78//usage: "\n -v Select non-matching lines"
79//usage: "\n -s Suppress open and read errors" 79//usage: "\n -s Suppress open and read errors"
80//usage: "\n -r Recurse" 80//usage: "\n -r Recurse"
81//usage: "\n -R Recurse and dereference symlinks"
81//usage: "\n -i Ignore case" 82//usage: "\n -i Ignore case"
82//usage: "\n -w Match whole words only" 83//usage: "\n -w Match whole words only"
83//usage: "\n -x Match whole lines only" 84//usage: "\n -x Match whole lines only"
@@ -108,7 +109,7 @@
108 109
109/* -e,-f are lists; -m,-A,-B,-C have numeric param */ 110/* -e,-f are lists; -m,-A,-B,-C have numeric param */
110#define OPTSTR_GREP \ 111#define OPTSTR_GREP \
111 "lnqvscFiHhe:*f:*Lorm:+wx" \ 112 "lnqvscFiHhe:*f:*LorRm:+wx" \
112 IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ 113 IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
113 "E" \ 114 "E" \
114 IF_EXTRA_COMPAT("z") \ 115 IF_EXTRA_COMPAT("z") \
@@ -131,6 +132,7 @@ enum {
131 OPTBIT_L, /* list unmatched file names only */ 132 OPTBIT_L, /* list unmatched file names only */
132 OPTBIT_o, /* show only matching parts of lines */ 133 OPTBIT_o, /* show only matching parts of lines */
133 OPTBIT_r, /* recurse dirs */ 134 OPTBIT_r, /* recurse dirs */
135 OPTBIT_R, /* recurse dirs and symlinks to dirs */
134 OPTBIT_m, /* -m MAX_MATCHES */ 136 OPTBIT_m, /* -m MAX_MATCHES */
135 OPTBIT_w, /* -w whole word match */ 137 OPTBIT_w, /* -w whole word match */
136 OPTBIT_x, /* -x whole line match */ 138 OPTBIT_x, /* -x whole line match */
@@ -154,6 +156,7 @@ enum {
154 OPT_L = 1 << OPTBIT_L, 156 OPT_L = 1 << OPTBIT_L,
155 OPT_o = 1 << OPTBIT_o, 157 OPT_o = 1 << OPTBIT_o,
156 OPT_r = 1 << OPTBIT_r, 158 OPT_r = 1 << OPTBIT_r,
159 OPT_R = 1 << OPTBIT_R,
157 OPT_m = 1 << OPTBIT_m, 160 OPT_m = 1 << OPTBIT_m,
158 OPT_w = 1 << OPTBIT_w, 161 OPT_w = 1 << OPTBIT_w,
159 OPT_x = 1 << OPTBIT_x, 162 OPT_x = 1 << OPTBIT_x,
@@ -687,6 +690,7 @@ static int grep_dir(const char *dir)
687 int matched = 0; 690 int matched = 0;
688 recursive_action(dir, 691 recursive_action(dir,
689 /* recurse=yes */ ACTION_RECURSE | 692 /* recurse=yes */ ACTION_RECURSE |
693 /* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) |
690 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 | 694 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
691 /* depthFirst=yes */ ACTION_DEPTHFIRST, 695 /* depthFirst=yes */ ACTION_DEPTHFIRST,
692 /* fileAction= */ file_action_grep, 696 /* fileAction= */ file_action_grep,
@@ -827,7 +831,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
827 if (!cur_file || LONE_DASH(cur_file)) { 831 if (!cur_file || LONE_DASH(cur_file)) {
828 cur_file = "(standard input)"; 832 cur_file = "(standard input)";
829 } else { 833 } else {
830 if (option_mask32 & OPT_r) { 834 if (option_mask32 & (OPT_r|OPT_R)) {
831 struct stat st; 835 struct stat st;
832 if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) { 836 if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
833 if (!(option_mask32 & OPT_h)) 837 if (!(option_mask32 & OPT_h))