1
0

002-find-empty.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. diff -Nur busybox-1.17.0.orig/findutils/find.c busybox-1.17.0/findutils/find.c
  2. --- busybox-1.17.0.orig/findutils/find.c 2010-06-24 04:40:43.000000000 +0200
  3. +++ busybox-1.17.0/findutils/find.c 2010-07-08 12:33:55.759015289 +0200
  4. @@ -133,6 +133,14 @@
  5. //config: help
  6. //config: Support the 'find -inum' option for searching by inode number.
  7. //config:
  8. +//config:config FEATURE_FIND_EMPTY
  9. +//config: bool "Enable -empty option matching empty files and directories"
  10. +//config: default y
  11. +//config: depends on FIND
  12. +//config: help
  13. +//config: Support the 'find -empty' option for searching empty files
  14. +//config: and directories.
  15. +//config:
  16. //config:config FEATURE_FIND_EXEC
  17. //config: bool "Enable -exec: execute commands"
  18. //config: default y
  19. @@ -270,6 +278,7 @@
  20. IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
  21. IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
  22. IF_FEATURE_FIND_PRUNE( ACTS(prune))
  23. +IF_FEATURE_FIND_EMPTY( ACTS(empty))
  24. IF_FEATURE_FIND_DELETE( ACTS(delete))
  25. IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
  26. IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
  27. @@ -519,6 +528,34 @@
  28. return exec_actions(ap->subexpr, fileName, statbuf);
  29. }
  30. #endif
  31. +#if ENABLE_FEATURE_FIND_EMPTY
  32. +ACTF(empty)
  33. +{
  34. + DIR *d;
  35. + struct dirent *dp;
  36. + bool empty = TRUE;
  37. +
  38. + if (S_ISDIR(statbuf->st_mode)) {
  39. + d = opendir(fileName);
  40. + if (d == NULL)
  41. + bb_simple_perror_msg(fileName);
  42. + for (dp = readdir(d); dp; dp = readdir(d)) {
  43. + if (dp->d_name[0] != '.' ||
  44. + (dp->d_name[1] != '\0' &&
  45. + (dp->d_name[1] != '.' ||
  46. + dp->d_name[2] != '\0'))) {
  47. + empty = FALSE;
  48. + break;
  49. + }
  50. + }
  51. + closedir(d);
  52. + return(empty);
  53. + } else if (S_ISREG(statbuf->st_mode))
  54. + return (statbuf->st_size == 0);
  55. + else
  56. + return FALSE;
  57. +}
  58. +#endif
  59. #if ENABLE_FEATURE_FIND_SIZE
  60. ACTF(size)
  61. {
  62. @@ -686,6 +723,7 @@
  63. IF_FEATURE_FIND_PRINT0( PARM_print0 ,)
  64. IF_FEATURE_FIND_DEPTH( PARM_depth ,)
  65. IF_FEATURE_FIND_PRUNE( PARM_prune ,)
  66. + IF_FEATURE_FIND_EMPTY( PARM_empty ,)
  67. IF_FEATURE_FIND_DELETE( PARM_delete ,)
  68. IF_FEATURE_FIND_EXEC( PARM_exec ,)
  69. IF_FEATURE_FIND_PAREN( PARM_char_brace,)
  70. @@ -720,6 +758,7 @@
  71. IF_FEATURE_FIND_PRINT0( "-print0\0" )
  72. IF_FEATURE_FIND_DEPTH( "-depth\0" )
  73. IF_FEATURE_FIND_PRUNE( "-prune\0" )
  74. + IF_FEATURE_FIND_EMPTY( "-empty\0" )
  75. IF_FEATURE_FIND_DELETE( "-delete\0" )
  76. IF_FEATURE_FIND_EXEC( "-exec\0" )
  77. IF_FEATURE_FIND_PAREN( "(\0" )
  78. @@ -839,6 +878,12 @@
  79. (void) ALLOC_ACTION(prune);
  80. }
  81. #endif
  82. +#if ENABLE_FEATURE_FIND_EMPTY
  83. + else if (parm == PARM_empty) {
  84. + IF_FEATURE_FIND_NOT( invert_flag = 0; )
  85. + (void) ALLOC_ACTION(empty);
  86. + }
  87. +#endif
  88. #if ENABLE_FEATURE_FIND_DELETE
  89. else if (parm == PARM_delete) {
  90. G.need_print = 0;