Skip to content

Commit f98a1c4

Browse files
committed
Revert "exec: Don't flush if the user says no to -ok"
From the bfs_ctx_flush() implementation: // Before executing anything, flush all open streams. This ensures that // - the user sees everything relevant before an -ok[dir] prompt But that only works if we call it before the prompt. This reverts commit 21344df.
1 parent 8aea34d commit f98a1c4

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ static void bfs_exec_closewd(struct bfs_exec *execbuf, const struct BFTW *ftwbuf
352352

353353
/** Actually spawn the process. */
354354
static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
355+
// Flush the context state for consistency with the external process
356+
bfs_ctx_flush(execbuf->ctx);
357+
355358
if (execbuf->flags & BFS_EXEC_CONFIRM) {
356359
for (size_t i = 0; i < execbuf->argc; ++i) {
357360
if (fprintf(stderr, "%s ", execbuf->argv[i]) < 0) {
@@ -368,9 +371,6 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
368371
}
369372
}
370373

371-
// Flush cached state for consistency with the external process
372-
bfs_ctx_flush(execbuf->ctx);
373-
374374
if (execbuf->flags & BFS_EXEC_MULTI) {
375375
bfs_exec_debug(execbuf, "Executing '%s' ... [%zu arguments] (size %zu)\n",
376376
execbuf->argv[0], execbuf->argc - 1, execbuf->arg_size);

tests/gnu/exec_flush.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IO streams should be flushed before executing programs
1+
# I/O streams should be flushed before executing programs
22
invoke_bfs basic -print0 -exec echo found \; | tr '\0' ' ' >"$OUT"
33
sort_output
44
diff_output

tests/gnu/ok_flush.out

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
basic ? found
2+
basic/a ? found
3+
basic/b ? found
4+
basic/c ? found
5+
basic/c/d ? found
6+
basic/e ? found
7+
basic/e/f ? found
8+
basic/g ? found
9+
basic/g/h ? found
10+
basic/i ? found
11+
basic/j ? found
12+
basic/j/foo ? found
13+
basic/k ? found
14+
basic/k/foo ? found
15+
basic/k/foo/bar ? found
16+
basic/l ? found
17+
basic/l/foo ? found
18+
basic/l/foo/bar ? found
19+
basic/l/foo/bar/baz ? found

tests/gnu/ok_flush.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# I/O streams should be flushed before -ok prompts
2+
yes | invoke_bfs basic -printf '%p ? ' -ok echo found \; 2>&1 | tr '\0' ' ' | sed 's/?.*?/?/' >"$OUT"
3+
sort_output
4+
diff_output

0 commit comments

Comments
 (0)