diff options
author | Kyle J Harper <KyleJHarper@gmail.com> | 2015-04-12 23:41:55 (GMT) |
---|---|---|
committer | Kyle J Harper <KyleJHarper@gmail.com> | 2015-04-12 23:41:55 (GMT) |
commit | 7f2f1fcd5541976e79026ba00465f54b41ae29c2 (patch) | |
tree | 573085747ba439db95faa5ecfabd6f82f25b70e8 | |
parent | 0169502b49dfa5eb8878f5c85be3270012266fc3 (diff) | |
download | lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.zip lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.tar.gz lz4-7f2f1fcd5541976e79026ba00465f54b41ae29c2.tar.bz2 |
Added support for continuation of file compression and decompression if input files are missing. Should more closely match gzip/bzip2/xz and so forth. Also removed a debug print accidentally left in.
-rw-r--r-- | programs/lz4cli.c | 8 | ||||
-rw-r--r-- | programs/lz4io.c | 25 |
2 files changed, 27 insertions, 6 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c index f7cf27e..f3524b3 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -265,7 +265,8 @@ int main(int argc, char** argv) forceStdout=0, forceCompress=0, main_pause=0, - multiple_inputs=0; + multiple_inputs=0, + multiple_rv=0; const char* input_filename=0; const char* output_filename=0; char* dynNameSpace=0; @@ -518,7 +519,7 @@ int main(int argc, char** argv) if (decode) { if (multiple_inputs) - LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); + multiple_rv = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); else DEFAULT_DECOMPRESSOR(input_filename, output_filename); } @@ -533,7 +534,7 @@ int main(int argc, char** argv) else { if (multiple_inputs) - LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); + multiple_rv = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); else DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); } @@ -542,5 +543,6 @@ int main(int argc, char** argv) if (main_pause) waitEnter(); free(dynNameSpace); free((void*)inFileNames); + if (multiple_rv != 0) return multiple_rv; return 0; } diff --git a/programs/lz4io.c b/programs/lz4io.c index 16a588c..d399c90 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -501,12 +501,21 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel) { int i; + int missing_files = 0; + FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); for (i=0; i<ifntSize; i++) { + ifp = fopen(inFileNamesTable[i], "r"); + if (ifp == NULL) { + DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]); + missing_files++; + continue; + } + fclose(ifp); size_t ifnSize = strlen(inFileNamesTable[i]); if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } strcpy(outFileName, inFileNamesTable[i]); @@ -514,6 +523,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel); } free(outFileName); + if (missing_files > 0) return 1; return 0; } @@ -521,6 +531,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz { int i; int skipped_files = 0; + int missing_files = 0; + FILE *ifp; char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; size_t suffixSize = strlen(suffix); @@ -528,13 +540,19 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz for (i=0; i<ifntSize; i++) { + ifp = fopen(inFileNamesTable[i], "r"); + if (ifp == NULL) { + DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]); + missing_files++; + continue; + } + fclose(ifp); size_t ifnSize = strlen(inFileNamesTable[i]); strcpy(ifnSuffix, inFileNamesTable[i] + ifnSize - suffixSize); - DISPLAYLEVEL(2, "ifnSuffix is %s\n", ifnSuffix); if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } if (ifnSize <= suffixSize || strcmp(ifnSuffix, suffix) != 0) { DISPLAYLEVEL(2, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]); - skipped_files = 1; + skipped_files++; continue; } memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize); @@ -542,7 +560,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz LZ4IO_decompressFilename(inFileNamesTable[i], outFileName); } free(outFileName); - if (skipped_files) return 1; + if (skipped_files > 0) return 1; + if (missing_files > 0) return 1; return 0; } |