Merge pull request #1220 from felixhandte/list-stdin-check

Allow Invoking `zstd --list` When `stdin` is not a `tty`
This commit is contained in:
Yann Collet 2018-06-29 14:08:45 -07:00 committed by GitHub
commit 7cecc44de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 9 deletions

View File

@ -10,7 +10,7 @@ addons:
matrix: matrix:
include: include:
# Ubuntu 14.04 # Ubuntu 14.04
- env: Cmd='make gcc6install && CC=gcc-6 make -j all && make clean && CC=gcc-6 make clean uasan-test-zstd' - env: Cmd='make gcc6install && CC=gcc-6 make -j all && make clean && CC=gcc-6 make clean uasan-test-zstd </dev/null' # also test when stdin is not a tty
- env: Cmd='make gcc6install libc6install && CC=gcc-6 make clean uasan-test-zstd32' - env: Cmd='make gcc6install libc6install && CC=gcc-6 make clean uasan-test-zstd32'
- env: Cmd='make gcc7install && CC=gcc-7 make clean uasan-test-zstd' - env: Cmd='make gcc7install && CC=gcc-7 make clean uasan-test-zstd'
- env: Cmd='make clang38install && CC=clang-3.8 make clean msan-test-zstd' - env: Cmd='make clang38install && CC=clang-3.8 make clean msan-test-zstd'

View File

@ -2017,21 +2017,25 @@ static int FIO_listFile(fileInfo_t* total, const char* inFileName, int displayLe
} }
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel){ int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel){
unsigned u;
if (!IS_CONSOLE(stdin)) { for (u=0; u<numFiles;u++) {
if (!strcmp (filenameTable[u], stdinmark)) {
DISPLAYOUT("zstd: --list does not support reading from standard input\n"); DISPLAYOUT("zstd: --list does not support reading from standard input\n");
return 1; return 1;
} }
}
if (numFiles == 0) { if (numFiles == 0) {
if (!IS_CONSOLE(stdin)) {
DISPLAYOUT("zstd: --list does not support reading from standard input\n");
}
DISPLAYOUT("No files given\n"); DISPLAYOUT("No files given\n");
return 0; return 1;
} }
if (displayLevel <= 2) { if (displayLevel <= 2) {
DISPLAYOUT("Frames Skips Compressed Uncompressed Ratio Check Filename\n"); DISPLAYOUT("Frames Skips Compressed Uncompressed Ratio Check Filename\n");
} }
{ int error = 0; { int error = 0;
unsigned u;
fileInfo_t total; fileInfo_t total;
memset(&total, 0, sizeof(total)); memset(&total, 0, sizeof(total));
total.usesCheck = 1; total.usesCheck = 1;

View File

@ -731,8 +731,14 @@ $ECHO "\n===> zstd --list/-l error detection tests "
! $ZSTD -lv tmp1* ! $ZSTD -lv tmp1*
! $ZSTD --list -v tmp2 tmp12.zst ! $ZSTD --list -v tmp2 tmp12.zst
$ECHO "\n===> zstd --list/-l exits 1 when stdin is piped in" $ECHO "\n===> zstd --list/-l errors when presented with stdin / no files"
! echo "piped STDIN" | $ZSTD --list ! $ZSTD -l
! $ZSTD -l -
! $ZSTD -l < tmp1.zst
! $ZSTD -l - < tmp1.zst
! $ZSTD -l - tmp1.zst
! $ZSTD -l - tmp1.zst < tmp1.zst
$ZSTD -l tmp1.zst < tmp1.zst # but doesn't error just because stdin is not a tty
$ECHO "\n===> zstd --list/-l test with null files " $ECHO "\n===> zstd --list/-l test with null files "
./datagen -g0 > tmp5 ./datagen -g0 > tmp5