diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-07-29 21:09:30 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-07-29 21:09:30 -0400 |
commit | 758bb619e8631be1773cbecb4226580c83a41651 (patch) | |
tree | e3579bc9c916dcdbfa15a8b6c435e4793f16e593 | |
parent | 803edcab57b8d90897f9bc96affe8b4fb0ba468a (diff) | |
download | bfs-758bb619e8631be1773cbecb4226580c83a41651.tar.xz |
exec: Fix more corner cases with -ok ... +
-ok should look for a ; even if it sees {} +, according to POSIX.
-rw-r--r-- | exec.c | 19 | ||||
-rwxr-xr-x | tests.sh | 10 | ||||
-rw-r--r-- | tests/test_ok_plus_semicolon.out | 19 | ||||
-rw-r--r-- | tests/test_okdir_plus_semicolon.out | 19 |
4 files changed, 58 insertions, 9 deletions
@@ -127,21 +127,22 @@ struct bfs_exec *parse_bfs_exec(char **argv, enum bfs_exec_flags flags, const st for (i = 1; ; ++i) { const char *arg = argv[i]; if (!arg) { - cfprintf(cerr, "%{er}error: %s: Expected ';' or '+'.%{rs}\n", argv[0]); + if (execbuf->flags & BFS_EXEC_CONFIRM) { + cfprintf(cerr, "%{er}error: %s: Expected '... ;'.%{rs}\n", argv[0]); + } else { + cfprintf(cerr, "%{er}error: %s: Expected '... ;' or '... {} +'.%{rs}\n", argv[0]); + } goto fail; } else if (strcmp(arg, ";") == 0) { break; - } else if (strcmp(arg, "+") == 0 && strcmp(argv[i - 1], "{}") == 0) { - execbuf->flags |= BFS_EXEC_MULTI; - break; + } else if (strcmp(arg, "+") == 0) { + if (!(execbuf->flags & BFS_EXEC_CONFIRM) && strcmp(argv[i - 1], "{}") == 0) { + execbuf->flags |= BFS_EXEC_MULTI; + break; + } } } - if ((execbuf->flags & BFS_EXEC_CONFIRM) && (execbuf->flags & BFS_EXEC_MULTI)) { - cfprintf(cerr, "%{er}error: %s ... + is not supported.%{rs}\n", argv[0]); - goto fail; - } - execbuf->tmpl_argv = argv + 1; execbuf->tmpl_argc = i - 1; @@ -198,6 +198,7 @@ posix_tests=( test_perm_leading_plus_symbolic_minus test_permcopy test_ok_stdin + test_ok_plus_semicolon test_parens test_bang test_implicit_and @@ -307,6 +308,7 @@ gnu_tests=( test_execdir_slash test_execdir_slash_pwd test_execdir_slashes + test_okdir_plus_semicolon test_weird_names test_flag_weird_names test_follow_comma @@ -967,6 +969,14 @@ function test_okdir_stdin() { yes | bfs_diff basic -okdir bash -c "printf '%s? ' {} && head -n1" \; 2>/dev/null } +function test_ok_plus_semicolon() { + yes | bfs_diff basic -ok echo '{}' + \; 2>/dev/null +} + +function test_okdir_plus_semicolon() { + yes | bfs_diff basic -okdir echo '{}' + \; 2>/dev/null +} + function test_delete() { rm -rf scratch/* touchp scratch/foo/bar/baz diff --git a/tests/test_ok_plus_semicolon.out b/tests/test_ok_plus_semicolon.out new file mode 100644 index 0000000..85d27e5 --- /dev/null +++ b/tests/test_ok_plus_semicolon.out @@ -0,0 +1,19 @@ +basic + +basic/a + +basic/b + +basic/c + +basic/e + +basic/g + +basic/i + +basic/j + +basic/k + +basic/l + +basic/c/d + +basic/e/f + +basic/g/h + +basic/j/foo + +basic/k/foo + +basic/l/foo + +basic/k/foo/bar + +basic/l/foo/bar + +basic/l/foo/bar/baz + diff --git a/tests/test_okdir_plus_semicolon.out b/tests/test_okdir_plus_semicolon.out new file mode 100644 index 0000000..1909d27 --- /dev/null +++ b/tests/test_okdir_plus_semicolon.out @@ -0,0 +1,19 @@ +./a + +./b + +./bar + +./bar + +./basic + +./baz + +./c + +./d + +./e + +./f + +./foo + +./foo + +./foo + +./g + +./h + +./i + +./j + +./k + +./l + |