]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix for error message in recursive mode for an empty folder
authorbrailovich <91924341+brailovich@users.noreply.github.com>
Tue, 25 Jan 2022 01:42:21 +0000 (17:42 -0800)
committerGitHub <noreply@github.com>
Tue, 25 Jan 2022 01:42:21 +0000 (17:42 -0800)
-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

index fd563e1c24d0e47e2d930f80fb48bb7fdb4af894..34d2fa6e0d9575708d89b8cbf13e2d98b80f7bd0 100644 (file)
@@ -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 */