diff options
-rw-r--r-- | parse.c | 23 | ||||
-rwxr-xr-x | tests.sh | 24 |
2 files changed, 16 insertions, 31 deletions
@@ -336,9 +336,8 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * FILE *file = NULL; CFILE *cfile = NULL; - CFILE *dedup = NULL; - file = xfopen(path, O_WRONLY | O_CREAT | O_CLOEXEC); + file = xfopen(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC); if (!file) { goto fail; } @@ -348,18 +347,12 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * goto fail; } - dedup = bfs_ctx_dedup(ctx, cfile, path); + CFILE *dedup = bfs_ctx_dedup(ctx, cfile, path); if (!dedup) { goto fail; } - if (dedup == cfile) { - // O_TRUNC was omitted above to avoid repeatedly truncating the same file, so do it - // manually here - if (ftruncate(fileno(file), 0) != 0) { - goto fail; - } - } else { + if (dedup != cfile) { cfclose(cfile); } @@ -368,12 +361,10 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char * fail: parse_error(state, "${blu}%s${rs} ${bld}%s${rs}: %m.\n", expr->argv[0], path); - if (!dedup) { - if (cfile) { - cfclose(cfile); - } else if (file) { - fclose(file); - } + if (cfile) { + cfclose(cfile); + } else if (file) { + fclose(file); } return -1; } @@ -524,6 +524,7 @@ gnu_tests=( test_fprint test_fprint_duplicate test_fprint_error + test_fprint_noerror test_fprint_noarg test_fprint_nonexistent test_fprint_truncate @@ -736,7 +737,6 @@ bfs_tests=( test_execdir_plus - test_fprint_append test_fprint_duplicate_stdout test_fprint_error_stdout test_fprint_error_stderr @@ -1796,20 +1796,6 @@ function test_fprint_truncate() { fi } -function test_fprint_append() { - rm -f scratch/test_fprint_append.out - - invoke_bfs basic -fprint scratch/test_fprint_append.out >>scratch/test_fprint_append.out - invoke_bfs basic -fprint scratch/test_fprint_append.out >>scratch/test_fprint_append.out - sort -o scratch/test_fprint_append.out scratch/test_fprint_append.out - - if [ "$UPDATE" ]; then - cp {scratch,"$TESTS"}/test_fprint_append.out - else - diff -u {"$TESTS",scratch}/test_fprint_append.out - fi -} - function test_double_dash() { cd basic bfs_diff -- . -type f @@ -2724,6 +2710,14 @@ function test_fprint_error() { fi } +function test_fprint_noerror() { + # Regression test: /dev/full should not fail until actually written to + + if [ -e /dev/full ]; then + invoke_bfs basic -false -fprint /dev/full + fi +} + function test_fprint_error_stdout() { if [ -e /dev/full ]; then fail quiet invoke_bfs basic -maxdepth 0 -fprint /dev/full >/dev/full |