From 2c10bbd8666bb9944ff9c9a1adb5bfbced67e41e Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 2 Mar 2020 11:25:36 -0800 Subject: [PATCH 1/3] [zstdgrep] Log zstd decompression errors to stderr --- programs/zstdgrep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/zstdgrep b/programs/zstdgrep index 4879fb0da..cd6ed5495 100755 --- a/programs/zstdgrep +++ b/programs/zstdgrep @@ -109,7 +109,7 @@ if [ "$#" -lt 1 ]; then # ... on stdin set -f # Disable file name generation (globbing). # shellcheck disable=SC2086 - "${zcat}" -fq - | "${grep}" ${grep_args} -- "${pattern}" - + "${zcat}" -f - | "${grep}" ${grep_args} -- "${pattern}" - EXIT_CODE=$? set +f else @@ -121,9 +121,9 @@ else while [ "$#" -gt 0 ]; do # shellcheck disable=SC2086 if [ $pattern_found -eq 2 ]; then - "${zcat}" -fq -- "$1" | "${grep}" --label="${1}" ${grep_args} -- - + "${zcat}" -f -- "$1" | "${grep}" --label="${1}" ${grep_args} -- - else - "${zcat}" -fq -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" - + "${zcat}" -f -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" - fi [ "$?" -ne 0 ] && EXIT_CODE=1 shift From f589e2b5c8fc79fd07a82cb0431ff9851c0dd0bc Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 2 Mar 2020 11:30:12 -0800 Subject: [PATCH 2/3] [zstdgrep] Remove -f because zstdcat implies it --- programs/zstdgrep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/zstdgrep b/programs/zstdgrep index cd6ed5495..61efaa947 100755 --- a/programs/zstdgrep +++ b/programs/zstdgrep @@ -109,7 +109,7 @@ if [ "$#" -lt 1 ]; then # ... on stdin set -f # Disable file name generation (globbing). # shellcheck disable=SC2086 - "${zcat}" -f - | "${grep}" ${grep_args} -- "${pattern}" - + "${zcat}" - | "${grep}" ${grep_args} -- "${pattern}" - EXIT_CODE=$? set +f else @@ -121,9 +121,9 @@ else while [ "$#" -gt 0 ]; do # shellcheck disable=SC2086 if [ $pattern_found -eq 2 ]; then - "${zcat}" -f -- "$1" | "${grep}" --label="${1}" ${grep_args} -- - + "${zcat}" -- "$1" | "${grep}" --label="${1}" ${grep_args} -- - else - "${zcat}" -f -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" - + "${zcat}" -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" - fi [ "$?" -ne 0 ] && EXIT_CODE=1 shift From dbd6439bb6b2fac5a690ca825545888e123c045f Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 2 Mar 2020 13:04:37 -0800 Subject: [PATCH 3/3] [zstdgrep] Add a simple test --- tests/playTests.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/playTests.sh b/tests/playTests.sh index 09fe92fcf..c7605cc48 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -63,6 +63,7 @@ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) PRGDIR="$SCRIPT_DIR/../programs" TESTDIR="$SCRIPT_DIR/../tests" UNAME=$(uname) +ZSTDGREP="$PRGDIR/zstdgrep" detectedTerminal=false if [ -t 0 ] && [ -t 1 ] @@ -225,6 +226,17 @@ $ZSTD tmp -c --compress-literals -19 | $ZSTD -t $ZSTD -b --fast=1 -i0e1 tmp --compress-literals $ZSTD -b --fast=1 -i0e1 tmp --no-compress-literals +println "\n===> zstdgrep tests" +ln -sf $ZSTD_BIN zstdcat +rm -f tmp_grep +echo "1234" > tmp_grep +$ZSTD -f tmp_grep +lines=$(ZCAT=./zstdcat $ZSTDGREP 2>&1 "1234" tmp_grep tmp_grep.zst | wc -l) +test 2 -eq $lines +ZCAT=./zstdcat $ZSTDGREP 2>&1 "1234" tmp_grep_bad.zst && die "Should have failed" +ZCAT=./zstdcat $ZSTDGREP 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true +rm -f tmp_grep* + println "\n===> --exclude-compressed flag" rm -rf precompressedFilterTestDir mkdir -p precompressedFilterTestDir