[PATCH] find: implement -empty
Denys Vlasenko
vda.linux at googlemail.com
Thu Sep 12 10:05:39 UTC 2019
Applied, thanks
On Tue, Sep 10, 2019 at 10:06 PM Aaro Koskinen <aaro.koskinen at iki.fi> wrote:
>
> Implement -empty.
>
> Signed-off-by: Aaro Koskinen <aaro.koskinen at iki.fi>
> ---
> findutils/find.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/findutils/find.c b/findutils/find.c
> index d6679bd08..3e4ae3266 100644
> --- a/findutils/find.c
> +++ b/findutils/find.c
> @@ -203,6 +203,14 @@
> //config: WARNING: This option can do much harm if used wrong. Busybox will not
> //config: try to protect the user from doing stupid things. Use with care.
> //config:
> +//config:config FEATURE_FIND_EMPTY
> +//config: bool "Enable -empty: match empty files or directories"
> +//config: default y
> +//config: depends on FIND
> +//config: help
> +//config: Support the 'find -empty' option to find empty regular files
> +//config: or directories.
> +//config:
> //config:config FEATURE_FIND_PATH
> //config: bool "Enable -path: match pathname with shell pattern"
> //config: default y
> @@ -333,6 +341,9 @@
> //usage: IF_FEATURE_FIND_DELETE(
> //usage: "\n -delete Delete current file/directory. Turns on -depth option"
> //usage: )
> +//usage: IF_FEATURE_FIND_EMPTY(
> +//usage: "\n -empty Match empty file/directory."
> +//usage: )
> //usage: IF_FEATURE_FIND_QUIT(
> //usage: "\n -quit Exit"
> //usage: )
> @@ -396,6 +407,7 @@ IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
> IF_FEATURE_FIND_PRUNE( ACTS(prune))
> IF_FEATURE_FIND_QUIT( ACTS(quit))
> IF_FEATURE_FIND_DELETE( ACTS(delete))
> +IF_FEATURE_FIND_EMPTY( ACTS(empty))
> IF_FEATURE_FIND_EXEC( ACTS(exec,
> char **exec_argv; /* -exec ARGS */
> unsigned *subst_count;
> @@ -824,6 +836,31 @@ ACTF(delete)
> return TRUE;
> }
> #endif
> +#if ENABLE_FEATURE_FIND_EMPTY
> +ACTF(empty)
> +{
> + if (S_ISDIR(statbuf->st_mode)) {
> + DIR *dir;
> +
> + dir = opendir(fileName);
> + if (!dir) {
> + bb_simple_perror_msg(fileName);
> + return FALSE;
> + } else {
> + struct dirent *dent;
> + char n = 0;
> +
> + while ((dent = readdir(dir)) != NULL &&
> + DOT_OR_DOTDOT(dent->d_name) &&
> + n++ < 2)
> + ;
> + closedir(dir);
> + return !dent;
> + }
> + }
> + return S_ISREG(statbuf->st_mode) && !statbuf->st_size;
> +}
> +#endif
> #if ENABLE_FEATURE_FIND_CONTEXT
> ACTF(context)
> {
> @@ -989,6 +1026,7 @@ static action*** parse_params(char **argv)
> IF_FEATURE_FIND_PRUNE( PARM_prune ,)
> IF_FEATURE_FIND_QUIT( PARM_quit ,)
> IF_FEATURE_FIND_DELETE( PARM_delete ,)
> + IF_FEATURE_FIND_EMPTY( PARM_empty ,)
> IF_FEATURE_FIND_EXEC( PARM_exec ,)
> IF_FEATURE_FIND_EXECUTABLE(PARM_executable,)
> IF_FEATURE_FIND_PAREN( PARM_char_brace,)
> @@ -1034,6 +1072,7 @@ static action*** parse_params(char **argv)
> IF_FEATURE_FIND_PRUNE( "-prune\0" )
> IF_FEATURE_FIND_QUIT( "-quit\0" )
> IF_FEATURE_FIND_DELETE( "-delete\0" )
> + IF_FEATURE_FIND_EMPTY( "-empty\0" )
> IF_FEATURE_FIND_EXEC( "-exec\0" )
> IF_FEATURE_FIND_EXECUTABLE("-executable\0")
> IF_FEATURE_FIND_PAREN( "(\0" )
> @@ -1203,6 +1242,12 @@ static action*** parse_params(char **argv)
> (void) ALLOC_ACTION(delete);
> }
> #endif
> +#if ENABLE_FEATURE_FIND_EMPTY
> + else if (parm == PARM_empty) {
> + dbg("%d", __LINE__);
> + (void) ALLOC_ACTION(empty);
> + }
> +#endif
> #if ENABLE_FEATURE_FIND_EXEC
> else if (parm == PARM_exec) {
> int i;
> --
> 2.17.0
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list