From ddd1ab710c58f8fc8613ede1e2217bc5fadc360c Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 16:53:03 -0700 Subject: [PATCH 1/6] added tests in playTest.sh --- tests/playTests.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/playTests.sh b/tests/playTests.sh index e6957458..6b794f6d 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -537,6 +537,29 @@ fi rm tmp* +$ECHO "\n**** zstd --list/-l single frame tests ****" +./datagen > tmp1 +./datagen > tmp2 +./datagen > tmp3 +./datagen > tmp4 +$ZSTD tmp* +$ZSTD -l tmp* +$ZSTD -lv tmp* +$ZSTD --list tmp* +$ZSTD --list -v tmp* + +$ECHO "\n**** zstd --list/-l multiple frame tests ****" +cat tmp1.zst tmp2.zst > tmp12.zst +cat tmp3.zst tmp4.zst > tmp34.zst +cat tmp12.zst tmp34.zst > tmp1234.zst +cat tmp12.zst tmp4.zst > tmp124.zst +$ZSTD -l tmp* +$ZSTD -lv tmp* +$ZSTD --list tmp* +$ZSTD --list -v tmp* + +rm tmp* + if [ "$1" != "--test-large-data" ]; then $ECHO "Skipping large data tests" exit 0 From 60a2e55e2e2c7ffeb978d944a31696f2b7c5bcc1 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 17:00:59 -0700 Subject: [PATCH 2/6] added case for when file is not compressed with zstd (incorrect magic number) --- programs/fileio.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index bb3f13d8..908e0edb 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -874,7 +874,7 @@ typedef struct { /* * Reads information from file, stores in *info - * if successful, returns 0, otherwise returns 1 + * if successful, returns 0, returns 1 for frame analysis error, returns 2 for file not compressed with zstd */ static int getFileInfo(fileInfo_t* info, const char* inFileName){ int detectError = 0; @@ -998,6 +998,10 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){ } info->numSkippableFrames++; } + else { + detectError = 2; + break; + } } } fclose(srcFile); @@ -1043,8 +1047,12 @@ int FIO_listFile(const char* inFileName, int displayLevel){ { int const error = getFileInfo(&info, inFileName); if (error == 1) { + /* display error, but provide output */ DISPLAY("An error occurred with getting file info\n"); - return 1; + } + else if (error == 2) { + DISPLAYOUT("File %s not compressed with zstd\n\n", inFileName); + return 0; } } displayInfo(inFileName, &info, displayLevel); From b316691f9126711a2a68f7e0661194afd2b3fdf8 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 17:03:59 -0700 Subject: [PATCH 3/6] added const --- programs/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/fileio.c b/programs/fileio.c index 908e0edb..d807cffc 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -981,7 +981,7 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){ } else if (magicNumber == ZSTD_MAGIC_SKIPPABLE_START) { BYTE frameSizeBuffer[4]; - size_t readBytes = fread(frameSizeBuffer, 1, 4, srcFile); + size_t const readBytes = fread(frameSizeBuffer, 1, 4, srcFile); if (readBytes != 4) { DISPLAY("There was an error reading skippable frame size"); detectError = 1; From d3b34e4a2516418c4589812fc2e98f6f9bd461d8 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 17:12:41 -0700 Subject: [PATCH 4/6] changed spacing on if statements --- programs/fileio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index d807cffc..8db61a6f 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -893,7 +893,7 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){ BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]; size_t const numBytesRead = fread(headerBuffer, 1, sizeof(headerBuffer), srcFile); if (numBytesRead < ZSTD_frameHeaderSize_min) { - if(feof(srcFile)){ + if (feof(srcFile)) { break; } else{ @@ -1012,7 +1012,7 @@ static void displayInfo(const char* inFileName, fileInfo_t* info, int displayLev double const compressedSizeMB = (double)info->compressedSize/(1 MB); double const decompressedSizeMB = (double)info->decompressedSize/(1 MB); const char* checkString = (info->usesCheck ? "XXH64" : "None"); - if(displayLevel<=2){ + if (displayLevel <= 2) { if (info->canComputeDecompSize) { DISPLAYOUT("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n"); DISPLAYOUT("%9d %13d %7.2f MB %9.2f MB %5.3f %s %s\n", From 0d7c4d766ab9358b58e193b579578b6442e2f8fd Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 17:30:18 -0700 Subject: [PATCH 5/6] initialized info manually to avoid error --- programs/fileio.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 8db61a6f..5ab3c5be 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -884,10 +884,6 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){ return 1; } info->compressedSize = (unsigned long long)UTIL_getFileSize(inFileName); - info->decompressedSize = 0; - info->numActualFrames = 0; - info->numSkippableFrames = 0; - info->canComputeDecompSize = 1; /* begin analyzing frame */ for( ; ; ){ BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]; @@ -1014,10 +1010,11 @@ static void displayInfo(const char* inFileName, fileInfo_t* info, int displayLev const char* checkString = (info->usesCheck ? "XXH64" : "None"); if (displayLevel <= 2) { if (info->canComputeDecompSize) { + double const ratio = (info->decompressedSize == 0) ? 0.0 : compressedSizeMB/decompressedSizeMB; DISPLAYOUT("Skippable Non-Skippable Compressed Uncompressed Ratio Check Filename\n"); DISPLAYOUT("%9d %13d %7.2f MB %9.2f MB %5.3f %s %s\n", info->numSkippableFrames, info->numActualFrames, compressedSizeMB, decompressedSizeMB, - compressedSizeMB/decompressedSizeMB, checkString, inFileName); + ratio, checkString, inFileName); } else { DISPLAYOUT("Skippable Non-Skippable Compressed Check Filename\n"); @@ -1043,6 +1040,14 @@ static void displayInfo(const char* inFileName, fileInfo_t* info, int displayLev int FIO_listFile(const char* inFileName, int displayLevel){ fileInfo_t info; + + /* initialize info to avoid warnings */ + info.numActualFrames = 0; + info.numSkippableFrames = 0; + info.decompressedSize = 0; + info.canComputeDecompSize = 1; + info.compressedSize = 0; + info.usesCheck = 0; DISPLAYOUT("File: %s\n", inFileName); { int const error = getFileInfo(&info, inFileName); From b3e62446c67ff0b76eaf37be717f4c5a9c880260 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 15 Jun 2017 17:46:49 -0700 Subject: [PATCH 6/6] added in correct error return from main in zstdcli.c --- programs/fileio.c | 6 +++--- programs/zstdcli.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 5ab3c5be..2f51b95c 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1057,11 +1057,11 @@ int FIO_listFile(const char* inFileName, int displayLevel){ } else if (error == 2) { DISPLAYOUT("File %s not compressed with zstd\n\n", inFileName); - return 0; + return 1; } + displayInfo(inFileName, &info, displayLevel); + return error; } - displayInfo(inFileName, &info, displayLevel); - return 0; } int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFiles, diff --git a/programs/zstdcli.c b/programs/zstdcli.c index c71e80bd..a5564035 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -675,7 +675,7 @@ int main(int argCount, const char* argv[]) } } #endif - if(operation==zom_list){ + if (operation == zom_list) { g_displayOut = stdout; if(filenameIdx==0){ DISPLAY("No files given\n"); @@ -686,12 +686,13 @@ int main(int argCount, const char* argv[]) DISPLAY("===========================================\n"); DISPLAY("Number of files listed: %d\n", filenameIdx); { + int error = 0; unsigned u; for(u=0; u