aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2019-09-12 12:04:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-09-12 12:04:34 +0200
commitaf18b301eb16eb8496b31e5386b4c21c9045a5e6 (patch)
tree101c897b3462c117dc979f625ea46caa0fe3c0ae
parentd327c6b190900dcb0cb7cda9008eb4f9893a92d8 (diff)
downloadbusybox-w32-af18b301eb16eb8496b31e5386b4c21c9045a5e6.tar.gz
busybox-w32-af18b301eb16eb8496b31e5386b4c21c9045a5e6.tar.bz2
busybox-w32-af18b301eb16eb8496b31e5386b4c21c9045a5e6.zip
find: implement -empty
function old new delta func_empty - 121 +121 packed_usage 33154 33167 +13 parse_params 1490 1500 +10 static.params 228 235 +7 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/0 up/down: 151/0) Total: 151 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/findutils/find.c b/findutils/find.c
index d6679bd08..9a2c61b75 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;