When exec plus is used in parentetheses it is nested inside of ap->subexpr
so we need to flush these recurively.

For example this should print "a" but it didn't:
touch a
busybox find a \( -exec echo {} + \)

function                                             old     new   delta
flush_exec_plus                                        -     116    +116
put_cur_glyph_and_inc_cursor                         206     199      -7
input_tab                                           1111    1095     -16
find_main                                            575     506     -69
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 116/-92)            Total: 24 bytes
   text   data     bss     dec     hex  filename
1040512  16483    1840  1058835 102813  busybox_old
1040536  16483    1840  1058859 10282b  busybox_unstripped
---
 findutils/find.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/findutils/find.c b/findutils/find.c
index 31c996988..4818bce91 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -762,6 +762,12 @@ ACTF(samefile)
               statbuf->st_dev == ap->device;
 }
 #endif
+#if ENABLE_FEATURE_FIND_PAREN
+ACTF(paren)
+{
+       return exec_actions(ap->subexpr, fileName, statbuf);
+}
+#endif
 #if ENABLE_FEATURE_FIND_EXEC
 static int do_exec(action_exec *ap, const char *fileName)
 {
@@ -857,11 +863,10 @@ ACTF(exec)
        return do_exec(ap, fileName);
 }
 # if ENABLE_FEATURE_FIND_EXEC_PLUS
-static int flush_exec_plus(void)
+static int flush_exec_plus(action ***appp)
 {
        action *ap;
        action **app;
-       action ***appp = G.actions;
        while ((app = *appp++) != NULL) {
                while ((ap = *app++) != NULL) {
                        if (ap->f == (action_fp)func_exec) {
@@ -874,6 +879,10 @@ static int flush_exec_plus(void)
                                        if (rc == 0)
                                                return 1;
                                }
+# if ENABLE_FEATURE_FIND_PAREN
+                       } else if (ap->f == (action_fp)func_paren) {
+                               flush_exec_plus(((action_paren*)ap)->subexpr);
+# endif
                        }
                }
        }
@@ -905,12 +914,6 @@ ACTF(print)
        puts(fileName);
        return TRUE;
 }
-#if ENABLE_FEATURE_FIND_PAREN
-ACTF(paren)
-{
-       return exec_actions(ap->subexpr, fileName, statbuf);
-}
-#endif
 #if ENABLE_FEATURE_FIND_SIZE
 ACTF(size)
 {
@@ -1747,6 +1750,6 @@ int find_main(int argc UNUSED_PARAM, char **argv)
                }
        }
 
-       IF_FEATURE_FIND_EXEC_PLUS(G.exitstatus |= flush_exec_plus();)
+       IF_FEATURE_FIND_EXEC_PLUS(G.exitstatus |= flush_exec_plus(G.actions);)
        return G.exitstatus;
 }
-- 
2.46.2

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to