From 02433e0b1556c8c9d769471226b12209dd6512c8 Mon Sep 17 00:00:00 2001 From: Shashank Tavildar Date: Mon, 28 Oct 2019 14:54:54 -0700 Subject: [PATCH] Addressing comments: -Created a list of extensions defined in fileio.h, -Updated test --- programs/fileio.c | 9 +++++++-- programs/util.c | 17 ++++++++--------- programs/util.h | 19 +++++++++++++++---- programs/zstdcli.c | 2 +- tests/playTests.sh | 1 - 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index ff3401b5..7cbf0280 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1453,8 +1453,13 @@ FIO_compressFilename_srcFile(FIO_prefs_t* const prefs, ress.srcFile = FIO_openSrcFile(srcFileName); if (ress.srcFile == NULL) return 1; /* srcFile could not be opened */ - if (g_excludeCompressedFiles && !UTIL_isPrecompressedFile(srcFileName)) { /* precompressed file (--exclude-compressed). DO NOT COMPRESS */ - DISPLAYLEVEL(4, "Precompressed file: %s \n", srcFileName); + + /* Check if "srcFile" is compressed. Only done if --exclude-compressed flag is used + * YES => ZSTD will not compress the file. + * NO => ZSTD will resume with compress operation. + */ + if (g_excludeCompressedFiles && UTIL_isCompressedFile(srcFileName)) { /* precompressed file (--exclude-compressed). DO NOT COMPRESS */ + DISPLAYLEVEL(4, "File is already compressed : %s \n", srcFileName); fclose(ress.srcFile); ress.srcFile = NULL; return 0; diff --git a/programs/util.c b/programs/util.c index 830f2039..63e9ef9e 100644 --- a/programs/util.c +++ b/programs/util.c @@ -330,22 +330,21 @@ int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char YES => Skip the file (return 0) NO => return 1 */ -int UTIL_isPrecompressedFile(const char *inputName) +int UTIL_isCompressedFile(const char *inputName) { - return compareExtensions(inputName,compressedFileExtensions); + return compareExtensions(inputName,g_compressedFileExtensions); } -int compareExtensions(const char* infilename, const char extensionList[4][10]) +int compareExtensions(const char* infilename, const char* extensionList[]) { - int i=0; - //char* ext = strchr(infilename, '.'); - for(i=0;i<4;i++) + while(*extensionList != NULL) { - char* ext = strstr(infilename,extensionList[i]); + const char* ext = strstr(infilename,extensionList[i]); if(ext) - return 0; + return 1; + ++extensionList; } - return 1; + return 0; } /* * UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories, diff --git a/programs/util.h b/programs/util.h index 0da6255c..deb70786 100644 --- a/programs/util.h +++ b/programs/util.h @@ -39,7 +39,7 @@ extern "C" { #endif #include /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */ #include "mem.h" /* U32, U64 */ - +#include "fileio.h" /*-************************************************************ * Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW @@ -128,7 +128,18 @@ extern int g_utilDisplayLevel; #endif int g_excludeCompressedFiles; -static const char compressedFileExtensions[4][10] = {".zst",".gz",".xz",".lz4"}; +static const char *g_compressedFileExtensions[] = { + ZSTD_EXTENSION, + TZSTD_EXTENSION, + GZ_EXTENSION, + TGZ_EXTENSION, + LZMA_EXTENSION, + XZ_EXTENSION, + TXZ_EXTENSION, + LZ4_EXTENSION, + TLZ4_EXTENSION, + NULL +}; int UTIL_fileExist(const char* filename); int UTIL_isRegularFile(const char* infilename); @@ -137,8 +148,8 @@ U32 UTIL_isDirectory(const char* infilename); int UTIL_getFileStat(const char* infilename, stat_t* statbuf); int UTIL_isSameFile(const char* file1, const char* file2); int UTIL_compareStr(const void *p1, const void *p2); -int UTIL_isPrecompressedFile(const char* infilename); -int compareExtensions(const char* infilename, const char extensionList[4][10]); +int UTIL_isCompressedFile(const char* infilename); +int compareExtensions(const char* infilename, const char *extensionList[]); U32 UTIL_isFIFO(const char* infilename); U32 UTIL_isLink(const char* infilename); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 11116afc..a704a1ab 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -118,7 +118,6 @@ static int usage(const char* programName) #endif DISPLAY( " -D file: use `file` as Dictionary \n"); DISPLAY( " -o file: result stored into `file` (only if 1 input file) \n"); - DISPLAY( "--exclude-compressed: only compress files that are not previously compressed \n"); DISPLAY( " -f : overwrite output without prompting and (de)compress links \n"); DISPLAY( "--rm : remove source file(s) after successful de/compression \n"); DISPLAY( " -k : preserve source file(s) (default) \n"); @@ -137,6 +136,7 @@ static int usage_advanced(const char* programName) DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n"); DISPLAY( " -c : force write to standard output, even if it is the console\n"); DISPLAY( " -l : print information about zstd compressed files \n"); + DISPLAY( "--exclude-compressed: only compress files that are not previously compressed \n"); #ifndef ZSTD_NOCOMPRESS DISPLAY( "--ultra : enable levels beyond %i, up to %i (requires more memory)\n", ZSTDCLI_CLEVEL_MAX, ZSTD_maxCLevel()); DISPLAY( "--long[=#]: enable long distance matching with given window log (default: %u)\n", g_defaultMaxWindowLog); diff --git a/tests/playTests.sh b/tests/playTests.sh index 9294bf81..ca286071 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -232,7 +232,6 @@ else println "Test is not successful" fi println "Test completed" -sleep 5 println "test : file removal" $ZSTD -f --rm tmp