From 8a3974807e5393c9a9ffc857226d00ca0e62c722 Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Tue, 22 Oct 2019 15:23:22 -0700 Subject: [PATCH 1/3] Allowing named pipes to go through zstdcli --- programs/fileio.c | 2 +- programs/util.c | 13 +++++++++++++ programs/util.h | 1 + programs/zstdcli.c | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 8a45563d4..d45e4bbda 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -513,7 +513,7 @@ static FILE* FIO_openSrcFile(const char* srcFileName) return NULL; } - if (!UTIL_isRegularFile(srcFileName)) { + if (!UTIL_isRegularFile(srcFileName) && !UTIL_isFIFO(srcFileName)) { DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n", srcFileName); return NULL; diff --git a/programs/util.c b/programs/util.c index 3988295d4..5f97b1cde 100644 --- a/programs/util.c +++ b/programs/util.c @@ -115,6 +115,19 @@ int UTIL_isSameFile(const char* file1, const char* file2) #endif } +U32 UTIL_isFIFO(const char* infilename) +{ +/* macro guards, as defined in : https://linux.die.net/man/2/lstat */ +#if PLATFORM_POSIX_VERSION >= 200112L + stat_t statbuf; + int r = UTIL_getFileStat(infilename, &statbuf); + if (!r && S_ISFIFO(statbuf.st_mode)) return 1; +#endif + (void)infilename; + return 0; +} + + U32 UTIL_isLink(const char* infilename) { /* macro guards, as defined in : https://linux.die.net/man/2/lstat */ diff --git a/programs/util.h b/programs/util.h index 0080b63c7..3b15d9471 100644 --- a/programs/util.h +++ b/programs/util.h @@ -135,6 +135,7 @@ U32 UTIL_isDirectory(const char* infilename); int UTIL_getFileStat(const char* infilename, stat_t* statbuf); int UTIL_isSameFile(const char* file1, const char* file2); +U32 UTIL_isFIFO(const char* infilename); U32 UTIL_isLink(const char* infilename); #define UTIL_FILESIZE_UNKNOWN ((U64)(-1)) U64 UTIL_getFileSize(const char* infilename); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 98df728a9..7a0fa6a25 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -992,7 +992,7 @@ int main(int argCount, const char* argv[]) if (!followLinks) { unsigned u; for (u=0, fileNamesNb=0; u Date: Tue, 22 Oct 2019 16:15:59 -0700 Subject: [PATCH 2/3] Adding bash test for named pipes --- tests/Makefile | 4 +++- tests/playTests_bash.sh | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 tests/playTests_bash.sh diff --git a/tests/Makefile b/tests/Makefile index bd2f90976..123bd6312 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -335,7 +335,9 @@ test-zstd-nolegacy: zstd-nolegacy test-zstd test-zstd32 test-zstd-nolegacy: datagen file $(ZSTD) - ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST) + ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests_bash.sh $($(ZSTDRTTEST) + ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $($(ZSTDRTTEST) + test-gzstd: gzstd diff --git a/tests/playTests_bash.sh b/tests/playTests_bash.sh new file mode 100755 index 000000000..68bd17e9d --- /dev/null +++ b/tests/playTests_bash.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +println() { + printf '%b\n' "${*}" +} + +UNAME=$(uname) + +isWindows=false +INTOVOID="/dev/null" +case "$UNAME" in + GNU) DEVDEVICE="/dev/random" ;; + *) DEVDEVICE="/dev/zero" ;; +esac +case "$OS" in + Windows*) + isWindows=true + INTOVOID="NUL" + DEVDEVICE="NUL" + ;; +esac + +case "$UNAME" in + Darwin) MD5SUM="md5 -r" ;; + FreeBSD) MD5SUM="gmd5sum" ;; + OpenBSD) MD5SUM="md5" ;; + *) MD5SUM="md5sum" ;; +esac + +DIFF="diff" +case "$UNAME" in + SunOS) DIFF="gdiff" ;; +esac + +println "\nStarting playTests_bash.sh isWindows=$isWindows ZSTD='$ZSTD'" + +[ -n "$ZSTD" ] || die "ZSTD variable must be defined!" + +println "\n===> simple tests " + +println "\n===> zstd fifo named pipe test " +head -c 1M /dev/zero > tmp_original +$ZSTD <(head -c 1M /dev/zero) -o tmp_compressed +$ZSTD -d -o tmp_decompressed tmp_compressed +$DIFF -s tmp_original tmp_decompressed +rm -rf tmp* From 10f71470133cc5a3047e6666a004afef39d831bc Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Tue, 22 Oct 2019 17:09:44 -0700 Subject: [PATCH 3/3] Adding shell test and removing bash test file --- tests/Makefile | 4 +--- tests/playTests.sh | 10 +++++++++ tests/playTests_bash.sh | 46 ----------------------------------------- 3 files changed, 11 insertions(+), 49 deletions(-) delete mode 100755 tests/playTests_bash.sh diff --git a/tests/Makefile b/tests/Makefile index 123bd6312..bd2f90976 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -335,9 +335,7 @@ test-zstd-nolegacy: zstd-nolegacy test-zstd test-zstd32 test-zstd-nolegacy: datagen file $(ZSTD) - ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests_bash.sh $($(ZSTDRTTEST) - ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $($(ZSTDRTTEST) - + ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST) test-gzstd: gzstd diff --git a/tests/playTests.sh b/tests/playTests.sh index 5a47ceb5e..29ac1faa5 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -1080,4 +1080,14 @@ test -f dictionary rm -f tmp* dictionary +println "\n===> zstd fifo named pipe test " +head -c 10 /dev/zero > tmp_original +mkfifo named_pipe +head -c 10 /dev/zero > named_pipe & +$ZSTD named_pipe -o tmp_compressed +$ZSTD -d -o tmp_decompressed tmp_compressed +$DIFF -s tmp_original tmp_decompressed +rm -rf tmp* +rm -rf named_pipe + rm -f tmp* diff --git a/tests/playTests_bash.sh b/tests/playTests_bash.sh deleted file mode 100755 index 68bd17e9d..000000000 --- a/tests/playTests_bash.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -println() { - printf '%b\n' "${*}" -} - -UNAME=$(uname) - -isWindows=false -INTOVOID="/dev/null" -case "$UNAME" in - GNU) DEVDEVICE="/dev/random" ;; - *) DEVDEVICE="/dev/zero" ;; -esac -case "$OS" in - Windows*) - isWindows=true - INTOVOID="NUL" - DEVDEVICE="NUL" - ;; -esac - -case "$UNAME" in - Darwin) MD5SUM="md5 -r" ;; - FreeBSD) MD5SUM="gmd5sum" ;; - OpenBSD) MD5SUM="md5" ;; - *) MD5SUM="md5sum" ;; -esac - -DIFF="diff" -case "$UNAME" in - SunOS) DIFF="gdiff" ;; -esac - -println "\nStarting playTests_bash.sh isWindows=$isWindows ZSTD='$ZSTD'" - -[ -n "$ZSTD" ] || die "ZSTD variable must be defined!" - -println "\n===> simple tests " - -println "\n===> zstd fifo named pipe test " -head -c 1M /dev/zero > tmp_original -$ZSTD <(head -c 1M /dev/zero) -o tmp_compressed -$ZSTD -d -o tmp_decompressed tmp_compressed -$DIFF -s tmp_original tmp_decompressed -rm -rf tmp*