Skip to content

Commit

Permalink
Revert "exec: Don't flush if the user says no to -ok"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tavianator committed Nov 10, 2022
1 parent 8aea34d commit f98a1c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ static void bfs_exec_closewd(struct bfs_exec *execbuf, const struct BFTW *ftwbuf

/** Actually spawn the process. */
static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
// Flush the context state for consistency with the external process
bfs_ctx_flush(execbuf->ctx);

if (execbuf->flags & BFS_EXEC_CONFIRM) {
for (size_t i = 0; i < execbuf->argc; ++i) {
if (fprintf(stderr, "%s ", execbuf->argv[i]) < 0) {
Expand All @@ -368,9 +371,6 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) {
}
}

// Flush cached state for consistency with the external process
bfs_ctx_flush(execbuf->ctx);

if (execbuf->flags & BFS_EXEC_MULTI) {
bfs_exec_debug(execbuf, "Executing '%s' ... [%zu arguments] (size %zu)\n",
execbuf->argv[0], execbuf->argc - 1, execbuf->arg_size);
Expand Down
2 changes: 1 addition & 1 deletion tests/gnu/exec_flush.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IO streams should be flushed before executing programs
# I/O streams should be flushed before executing programs
invoke_bfs basic -print0 -exec echo found \; | tr '\0' ' ' >"$OUT"
sort_output
diff_output
19 changes: 19 additions & 0 deletions tests/gnu/ok_flush.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
basic ? found
basic/a ? found
basic/b ? found
basic/c ? found
basic/c/d ? found
basic/e ? found
basic/e/f ? found
basic/g ? found
basic/g/h ? found
basic/i ? found
basic/j ? found
basic/j/foo ? found
basic/k ? found
basic/k/foo ? found
basic/k/foo/bar ? found
basic/l ? found
basic/l/foo ? found
basic/l/foo/bar ? found
basic/l/foo/bar/baz ? found
4 changes: 4 additions & 0 deletions tests/gnu/ok_flush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# I/O streams should be flushed before -ok prompts
yes | invoke_bfs basic -printf '%p ? ' -ok echo found \; 2>&1 | tr '\0' ' ' | sed 's/?.*?/?/' >"$OUT"
sort_output
diff_output

0 comments on commit f98a1c4

Please sign in to comment.