fix zstd -l processing with closed stdin

This commit is contained in:
Pádraig Brady 2018-07-01 21:39:56 -07:00
parent e74f648564
commit 53ca653abf
2 changed files with 72 additions and 0 deletions

70
zstd-l-stdin.patch Normal file
View File

@ -0,0 +1,70 @@
From 712a9fd9721c314f4b0238577d803b012845f6d2 Mon Sep 17 00:00:00 2001
From: "W. Felix Handte" <w@felixhandte.com>
Date: Fri, 29 Jun 2018 15:33:44 -0400
Subject: [PATCH] Allow Invoking `zstd --list` When `stdin` is not a `tty`
Also now returns an error when no inputs are given.
New proposed behavior:
```
felix@odin:~/prog/zstd (list-stdin-check)$ ./zstd -l; echo $?
No files given
1
felix@odin:~/prog/zstd (list-stdin-check)$ ./zstd -l Makefile.zst; echo $?
Frames Skips Compressed Uncompressed Ratio Check Filename
1 0 3.08 KB 10.92 KB 3.544 XXH64 Makefile.zst
0
felix@odin:~/prog/zstd (list-stdin-check)$ ./zstd -l <Makefile.zst; echo $?
zstd: --list does not support reading from standard input
No files given
1
felix@odin:~/prog/zstd (list-stdin-check)$ ./zstd -l Makefile.zst <Makefile.zst; echo $?
Frames Skips Compressed Uncompressed Ratio Check Filename
1 0 3.08 KB 10.92 KB 3.544 XXH64 Makefile.zst
0
felix@odin:~/prog/zstd (list-stdin-check)$
```
---
programs/fileio.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/programs/fileio.c b/programs/fileio.c
index 0175b31..b4eed28 100644
--- a/programs/fileio.c
+++ b/programs/fileio.c
@@ -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){
-
- if (!IS_CONSOLE(stdin)) {
- DISPLAYOUT("zstd: --list does not support reading from standard input\n");
- return 1;
+ unsigned u;
+ for (u=0; u<numFiles;u++) {
+ if (!strcmp (filenameTable[u], stdinmark)) {
+ DISPLAYOUT("zstd: --list does not support reading from standard input\n");
+ return 1;
+ }
}
if (numFiles == 0) {
+ if (!IS_CONSOLE(stdin)) {
+ DISPLAYOUT("zstd: --list does not support reading from standard input\n");
+ }
DISPLAYOUT("No files given\n");
- return 0;
+ return 1;
}
if (displayLevel <= 2) {
DISPLAYOUT("Frames Skips Compressed Uncompressed Ratio Check Filename\n");
}
{ int error = 0;
- unsigned u;
fileInfo_t total;
memset(&total, 0, sizeof(total));
total.usesCheck = 1;
--
2.9.3

View File

@ -21,6 +21,7 @@ URL: https://github.com/facebook/zstd
Source0: https://github.com/facebook/zstd/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Patch1: pzstd.1.patch
Patch2: zstd-l-stdin.patch
BuildRequires: gcc gtest-devel
%if %{with pzstd}
@ -51,6 +52,7 @@ find -name .gitignore -delete
%if %{with pzstd}
%patch1 -p1
%endif
%patch2 -p1
%build
export CFLAGS="$RPM_OPT_FLAGS"