002-find-empty.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. diff -Nur busybox-1.12.3/findutils/Config.in busybox-1.12.3-find/findutils/Config.in
  2. --- busybox-1.12.3/findutils/Config.in 2008-09-28 20:04:28.000000000 +0200
  3. +++ busybox-1.12.3-find/findutils/Config.in 2009-01-06 22:24:46.086215240 +0100
  4. @@ -81,6 +81,14 @@
  5. help
  6. Support the 'find -inum' option for searching by inode number.
  7. +config FEATURE_FIND_EMPTY
  8. + bool "Enable -empty option matching empty files and directories"
  9. + default y
  10. + depends on FIND
  11. + help
  12. + Support the 'find -empty' option for searching empty files
  13. + and directories.
  14. +
  15. config FEATURE_FIND_EXEC
  16. bool "Enable -exec option allowing execution of commands"
  17. default y
  18. diff -Nur busybox-1.12.3/findutils/find.c busybox-1.12.3-find/findutils/find.c
  19. --- busybox-1.12.3/findutils/find.c 2008-09-28 20:04:28.000000000 +0200
  20. +++ busybox-1.12.3-find/findutils/find.c 2009-01-06 23:33:53.201386585 +0100
  21. @@ -93,6 +93,7 @@
  22. USE_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
  23. USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
  24. USE_FEATURE_FIND_PRUNE( ACTS(prune))
  25. +USE_FEATURE_FIND_EMPTY( ACTS(empty))
  26. USE_FEATURE_FIND_DELETE( ACTS(delete))
  27. USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
  28. USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
  29. @@ -318,6 +319,34 @@
  30. return exec_actions(ap->subexpr, fileName, statbuf);
  31. }
  32. #endif
  33. +#if ENABLE_FEATURE_FIND_EMPTY
  34. +ACTF(empty)
  35. +{
  36. + DIR *d;
  37. + struct dirent *dp;
  38. + bool empty = TRUE;
  39. +
  40. + if (S_ISDIR(statbuf->st_mode)) {
  41. + d = opendir(fileName);
  42. + if (d == NULL)
  43. + bb_simple_perror_msg(fileName);
  44. + for (dp = readdir(d); dp; dp = readdir(d)) {
  45. + if (dp->d_name[0] != '.' ||
  46. + (dp->d_name[1] != '\0' &&
  47. + (dp->d_name[1] != '.' ||
  48. + dp->d_name[2] != '\0'))) {
  49. + empty = FALSE;
  50. + break;
  51. + }
  52. + }
  53. + closedir(d);
  54. + return(empty);
  55. + } else if (S_ISREG(statbuf->st_mode))
  56. + return (statbuf->st_size == 0);
  57. + else
  58. + return FALSE;
  59. +}
  60. +#endif
  61. #if ENABLE_FEATURE_FIND_SIZE
  62. ACTF(size)
  63. {
  64. @@ -459,6 +488,7 @@
  65. USE_FEATURE_FIND_PRINT0( PARM_print0 ,)
  66. USE_FEATURE_FIND_DEPTH( PARM_depth ,)
  67. USE_FEATURE_FIND_PRUNE( PARM_prune ,)
  68. + USE_FEATURE_FIND_EMPTY( PARM_empty ,)
  69. USE_FEATURE_FIND_DELETE( PARM_delete ,)
  70. USE_FEATURE_FIND_EXEC( PARM_exec ,)
  71. USE_FEATURE_FIND_PAREN( PARM_char_brace,)
  72. @@ -492,6 +522,7 @@
  73. USE_FEATURE_FIND_PRINT0( "-print0\0" )
  74. USE_FEATURE_FIND_DEPTH( "-depth\0" )
  75. USE_FEATURE_FIND_PRUNE( "-prune\0" )
  76. + USE_FEATURE_FIND_EMPTY( "-empty\0" )
  77. USE_FEATURE_FIND_DELETE( "-delete\0" )
  78. USE_FEATURE_FIND_EXEC( "-exec\0" )
  79. USE_FEATURE_FIND_PAREN( "(\0" )
  80. @@ -610,6 +641,12 @@
  81. (void) ALLOC_ACTION(prune);
  82. }
  83. #endif
  84. +#if ENABLE_FEATURE_FIND_EMPTY
  85. + else if (parm == PARM_empty) {
  86. + USE_FEATURE_FIND_NOT( invert_flag = 0; )
  87. + (void) ALLOC_ACTION(empty);
  88. + }
  89. +#endif
  90. #if ENABLE_FEATURE_FIND_DELETE
  91. else if (parm == PARM_delete) {
  92. need_print = 0;
  93. diff -Nur busybox-1.12.3/include/usage.h busybox-1.12.3-find/include/usage.h
  94. --- busybox-1.12.3/include/usage.h 2008-09-28 20:04:26.000000000 +0200
  95. +++ busybox-1.12.3-find/include/usage.h 2009-01-07 00:07:49.832669156 +0100
  96. @@ -1140,6 +1140,8 @@
  97. "\n -group NAME File belongs to group NAME (numeric group ID allowed)") \
  98. USE_FEATURE_FIND_DEPTH( \
  99. "\n -depth Process directory name after traversing it") \
  100. + USE_FEATURE_FIND_EMPTY( \
  101. + "\n -empty File or directory is empty") \
  102. USE_FEATURE_FIND_SIZE( \
  103. "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))." \
  104. "\n +/-N: file size is bigger/smaller than N") \