Re: [PATCH] find: implement -empty

2019-09-12 Thread Denys Vlasenko
Applied, thanks

On Tue, Sep 10, 2019 at 10:06 PM Aaro Koskinen  wrote:
>
> Implement -empty.
>
> Signed-off-by: Aaro Koskinen 
> ---
>  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@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-12 Thread Denys Vlasenko
On Tue, Sep 10, 2019 at 10:06 PM Aaro Koskinen  wrote:
> Implement -empty.
>
> Signed-off-by: Aaro Koskinen 
> ---
>  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:   )

"""
If none of the following actions is specified, -print is assumed
-print  Print file name
-print0 Print file name, NUL terminated
-exec CMD ARG ; Run CMD with all instances of {} replaced by
file name. Fails if CMD exits with nonzero
-exec CMD ARG + Run CMD with {} replaced by list of file names
-delete Delete current file/directory. Turns on -depth option
-empty  Match empty file/directory.
-quit   Exit
"""

The above is wrong: -empty does not "turn off" implicit -print.
IOW: -empty help text should be above this block.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-12 Thread walter harms



Am 11.09.2019 17:25, schrieb Aaro Koskinen:
> Hi,
> 
> On Wed, Sep 11, 2019 at 09:46:45AM +0200, walter harms wrote:
>> is seems possible to simply that a bit (untested version):
>>
>> if ( ! S_ISDIR(statbuf->st_mode))
>>return S_ISREG(statbuf->st_mode) && !statbuf->st_size;
>>
>> DIR *dir;
> 
> Not sure if this is allowed by current busybox coding style:
> 
> findutils/find.c:844:2: warning: ISO C90 forbids mixed declarations and code 
> [-Wdeclaration-after-statement]
>   DIR *dir;
> 
> A.
> 

Hi,
same is true for struct dirent *dent;char n = 0;

It was only c i trust you that you can fix that if interested.

re,
 wh
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-11 Thread David Demelier

Le 11/09/2019 à 17:30, Aaro Koskinen a écrit :

Hi,

On Wed, Sep 11, 2019 at 03:22:33PM +0200, David Demelier wrote:

You can save an indent level here by removing this else block. Since there
is a return before, no need for this else.


The block is used to limit variable scope, so I don't have to declare
variables that are only used when else is taken. Though, on my compiler
it does not really matter, the generated code is the same.

A.


Ah that's true, I forgot that old C versions forbid declaration/definition.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-11 Thread Aaro Koskinen
Hi,

On Wed, Sep 11, 2019 at 03:22:33PM +0200, David Demelier wrote:
> You can save an indent level here by removing this else block. Since there
> is a return before, no need for this else.

The block is used to limit variable scope, so I don't have to declare
variables that are only used when else is taken. Though, on my compiler
it does not really matter, the generated code is the same.

A.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-11 Thread Aaro Koskinen
Hi,

On Wed, Sep 11, 2019 at 09:46:45AM +0200, walter harms wrote:
> is seems possible to simply that a bit (untested version):
> 
> if ( ! S_ISDIR(statbuf->st_mode))
>return S_ISREG(statbuf->st_mode) && !statbuf->st_size;
> 
> DIR *dir;

Not sure if this is allowed by current busybox coding style:

findutils/find.c:844:2: warning: ISO C90 forbids mixed declarations and code 
[-Wdeclaration-after-statement]
  DIR *dir;

A.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-11 Thread David Demelier

Le 10/09/2019 à 22:06, Aaro Koskinen a écrit :

+#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 {


You can save an indent level here by removing this else block. Since 
there is a return before, no need for this 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;
+}



___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-11 Thread walter harms



Am 10.09.2019 22:06, schrieb Aaro Koskinen:
> Implement -empty.
> 
> Signed-off-by: Aaro Koskinen 
> ---
>  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


is seems possible to simply that a bit (untested version):

if ( ! S_ISDIR(statbuf->st_mode))
   return S_ISREG(statbuf->st_mode) && !statbuf->st_size;


DIR *dir;

dir = opendir(fileName);
if (!dir) {
bb_simple_perror_msg(fileName);
return FALSE;
}

struct dirent *dent;
char n = 0;

while ((dent = readdir(dir)) != NULL &&
 DOT_OR_DOTDOT(dent->d_name) &&
  n++ < 2) ;;
closedir(dir);
return !dent;

JM2C,

re,
 wh



>  #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;
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] find: implement -empty

2019-09-10 Thread Tim Tassonis

On 9/10/19 10:06 PM, Aaro Koskinen wrote:

Implement -empty.

Signed-off-by: Aaro Koskinen 
---
  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;




Thanks a lot! Will try it out in a second.


Bye
Tim

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox