From: senhuang42 Date: Mon, 24 Aug 2020 23:10:03 +0000 (-0400) Subject: Add a warning whenever (de)compressing multiple files into one source, or into stdout X-Git-Tag: v1.4.7~87^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1acf2435400730869c6d22856251008dd98126d9;p=thirdparty%2Fzstd.git Add a warning whenever (de)compressing multiple files into one source, or into stdout --- diff --git a/programs/fileio.c b/programs/fileio.c index d5b8a7d14..bdf42543b 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1677,6 +1677,29 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs, /* init */ assert(outFileName != NULL || suffix != NULL); if (outFileName != NULL) { /* output into a single destination (stdout typically) */ + if (nbFiles > 1) { + if (!strcmp (outFileName, stdoutmark)) { + DISPLAY("zstd: WARNING: all input files will be processed and concatenated into stdout. "); + } else { + DISPLAY("zstd: WARNING: all input files will be processed and concatenated into a single output file: %s ", outFileName); + } + if (prefs->removeSrcFile && !prefs->overwrite) { + DISPLAY("\nYou must specify -f as well in order to execute this command with --rm. Aborting..."); + return 1; + } + + DISPLAY("Proceed? (y/n): "); + { + int ch = getchar(); + if ((ch != 'y') && (ch != 'Y')) { + DISPLAY("zstd: aborting...\n"); + return 1; + } + /* flush the rest */ + while ((ch!=EOF) && (ch!='\n')) + ch = getchar(); + } + } ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName); if (ress.dstFile == NULL) { /* could not open outFileName */ error = 1; diff --git a/tests/playTests.sh b/tests/playTests.sh index b7bfa76cd..b84cffd01 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -349,19 +349,25 @@ rm tmp* println "\n===> compress multiple files" println hello > tmp1 println world > tmp2 -zstd tmp1 tmp2 -o "$INTOVOID" -f -zstd tmp1 tmp2 -c | zstd -t -zstd tmp1 tmp2 -o tmp.zst +echo 'y' | zstd tmp1 tmp2 -o "$INTOVOID" -f # echo 'y' confirms the warning prompt +echo 'y' | zstd tmp1 tmp2 -c | zstd -t +echo 'y' | zstd tmp1 tmp2 -o tmp.zst test ! -f tmp1.zst test ! -f tmp2.zst zstd tmp1 tmp2 zstd -t tmp1.zst tmp2.zst zstd -dc tmp1.zst tmp2.zst -zstd tmp1.zst tmp2.zst -o "$INTOVOID" -f -zstd -d tmp1.zst tmp2.zst -o tmp +echo 'y' | zstd tmp1.zst tmp2.zst -o "$INTOVOID" -f +echo 'y' | zstd -d tmp1.zst tmp2.zst -o tmp touch tmpexists -zstd tmp1 tmp2 -f -o tmpexists -zstd tmp1 tmp2 -o tmpexists && die "should have refused to overwrite" +echo 'y' | zstd tmp1 tmp2 -f -o tmpexists +echo 'y' | zstd tmp1 tmp2 -o tmpexists && die "should have refused to overwrite" +zstd tmp1 tmp2 -o "$INTOVOID" --rm && die "should have refused to execute with --rm" +println gooder > tmp_rm1 +println boi > tmp_rm2 +echo 'y' | zstd tmp_rm1 tmp_rm2 -o tmp_rm3.zst -f --rm +rm tmp_rm3.zst + # Bug: PR #972 if [ "$?" -eq 139 ]; then die "should not have segfaulted" @@ -382,7 +388,7 @@ test -f tmp1 test -f tmp2 test -f tmp3 println "compress tmp* into stdout > tmpall : " -zstd -c tmp1 tmp2 tmp3 > tmpall +echo 'y' | zstd -c tmp1 tmp2 tmp3 > tmpall test -f tmpall # should check size of tmpall (should be tmp1.zst + tmp2.zst + tmp3.zst) println "decompress tmpall* into stdout > tmpdec : " cp tmpall tmpall2 @@ -920,7 +926,7 @@ datagen | zstd -c | zstd -t println "\n===> golden files tests " zstd -t -r "$TESTDIR/golden-decompression" -zstd -c -r "$TESTDIR/golden-compression" | zstd -t +echo 'y' | zstd -c -r "$TESTDIR/golden-compression" | zstd -t zstd -D "$TESTDIR/golden-dictionaries/http-dict-missing-symbols" "$TESTDIR/golden-compression/http" -c | zstd -D "$TESTDIR/golden-dictionaries/http-dict-missing-symbols" -t