From 4021b784376c3790c077e9b8deedbb6a4f016687 Mon Sep 17 00:00:00 2001 From: brailovich <91924341+brailovich@users.noreply.github.com> Date: Mon, 24 Jan 2022 17:42:21 -0800 Subject: [PATCH 1/5] fix for error message in recursive mode for an empty folder -r on empty directory resulted in zstd waiting input from stdin. now zstd exits without error and prints a warning message explaining why no processing happened (no files or directories to process). --- programs/zstdcli.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index fd563e1c24d..34d2fa6e0d9 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -834,6 +834,7 @@ int main(int argCount, const char* argv[]) size_t streamSrcSize = 0; size_t targetCBlockSize = 0; size_t srcSizeHint = 0; + size_t nbInputFileNames = 0; int dictCLevel = g_defaultDictCLevel; unsigned dictSelect = g_defaultSelectivityLevel; #ifndef ZSTD_NODICT @@ -1256,6 +1257,8 @@ int main(int argCount, const char* argv[]) } } + nbInputFileNames = filenames->tableSize; /* saving number of input files */ + if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */ UTIL_expandFNT(&filenames, followLinks); } @@ -1358,7 +1361,17 @@ int main(int argCount, const char* argv[]) #endif /* No input filename ==> use stdin and stdout */ - if (filenames->tableSize == 0) UTIL_refFilename(filenames, stdinmark); + if (filenames->tableSize == 0) { + /* It is possible that the input + was a number of empty directories. In this case + stdin and stdout should not be used */ + if (nbInputFileNames > 0 ){ + DISPLAYLEVEL(2, "please provide correct input file(s) or non-empty directories -- ignored \n"); + CLEAN_RETURN(2); + } + UTIL_refFilename(filenames, stdinmark); + } + if (!strcmp(filenames->fileNames[0], stdinmark) && !outFileName) outFileName = stdoutmark; /* when input is stdin, default output is stdout */ From beb48722411b53f36387c5c88ba9a9c7671c5c12 Mon Sep 17 00:00:00 2001 From: brailovich <91924341+brailovich@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:51:18 -0800 Subject: [PATCH 2/5] Update zstdcli.c --- programs/zstdcli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 34d2fa6e0d9..a8fc0d0486e 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -1366,8 +1366,8 @@ int main(int argCount, const char* argv[]) was a number of empty directories. In this case stdin and stdout should not be used */ if (nbInputFileNames > 0 ){ - DISPLAYLEVEL(2, "please provide correct input file(s) or non-empty directories -- ignored \n"); - CLEAN_RETURN(2); + DISPLAYLEVEL(1, "please provide correct input file(s) or non-empty directories -- ignored \n"); + CLEAN_RETURN(0); } UTIL_refFilename(filenames, stdinmark); } From 5e7523385b98afce31747be2a0569089539ceb8e Mon Sep 17 00:00:00 2001 From: brailovich <91924341+brailovich@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:53:11 -0800 Subject: [PATCH 3/5] Update playTests.sh --- tests/playTests.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/playTests.sh b/tests/playTests.sh index f19291a6063..5a45247b3b4 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -390,6 +390,18 @@ println "\n===> recursive mode test " # combination of -r with empty list of input file zstd -c -r < tmp > tmp.zst +# combination of -r with empty folder +mkdir -p tmpEmptyDir +zstd -r tmpEmptyDir 2>tmplog2 +if [grep "aborting" tmplog2]; then + println "Should not abort on empty directory" + rm -rf tmplog2 + rm -rf tmpEmptyDir + die +fi +rm -rf tmplog2 +rm -rf tmpEmptyDir + println "\n===> file removal" zstd -f --rm tmp From 501a353b9154e6885031fe14e2ded5760c97f854 Mon Sep 17 00:00:00 2001 From: brailovich <91924341+brailovich@users.noreply.github.com> Date: Wed, 26 Jan 2022 18:56:52 -0800 Subject: [PATCH 4/5] Update playTests.sh --- tests/playTests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/playTests.sh b/tests/playTests.sh index 5a45247b3b4..ba287403406 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -393,7 +393,7 @@ zstd -c -r < tmp > tmp.zst # combination of -r with empty folder mkdir -p tmpEmptyDir zstd -r tmpEmptyDir 2>tmplog2 -if [grep "aborting" tmplog2]; then +if [ grep "aborting" tmplog2 ]; then println "Should not abort on empty directory" rm -rf tmplog2 rm -rf tmpEmptyDir From 9f37d1fede5a3be4b16c10194306b1baa8a084f4 Mon Sep 17 00:00:00 2001 From: brailovich <91924341+brailovich@users.noreply.github.com> Date: Thu, 27 Jan 2022 08:22:05 -0800 Subject: [PATCH 5/5] Update playTests.sh combination of -r with empty folder simplified to comply with sh compatibility tests --- tests/playTests.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/playTests.sh b/tests/playTests.sh index ba287403406..e0d802f6ee3 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -392,14 +392,7 @@ zstd -c -r < tmp > tmp.zst # combination of -r with empty folder mkdir -p tmpEmptyDir -zstd -r tmpEmptyDir 2>tmplog2 -if [ grep "aborting" tmplog2 ]; then - println "Should not abort on empty directory" - rm -rf tmplog2 - rm -rf tmpEmptyDir - die -fi -rm -rf tmplog2 +zstd -r tmpEmptyDir rm -rf tmpEmptyDir