From: Felix Handte Date: Thu, 24 Oct 2019 21:49:34 +0000 (-0400) Subject: Merge branch 'tzst-ext-tmp' into tzst-ext X-Git-Tag: v1.4.4~1^2~10^2~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=506e1a11769cd5f57401354b8f58eb9b988890d3;p=thirdparty%2Fzstd.git Merge branch 'tzst-ext-tmp' into tzst-ext --- 506e1a11769cd5f57401354b8f58eb9b988890d3 diff --cc programs/fileio.c index 5aaad0e96,0365f1449..07503f052 --- a/programs/fileio.c +++ b/programs/fileio.c @@@ -2168,39 -2297,55 +2297,46 @@@ FIO_determineDstName(const char* srcFil { static size_t dfnbCapacity = 0; static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */ + char* outDirFilename = NULL; + + const char* SUFFIX_LIST = ZSTD_EXTENSION "/" TZSTD_EXTENSION + #ifdef ZSTD_GZDECOMPRESS + "/" GZ_EXTENSION "/" TGZ_EXTENSION + #endif + #ifdef ZSTD_LZMADECOMPRESS + "/" XZ_EXTENSION "/" LZMA_EXTENSION "/" TXZ_EXTENSION + #endif + #ifdef ZSTD_LZ4DECOMPRESS + "/" LZ4_EXTENSION "/" TLZ4_EXTENSION + #endif + ; + - size_t const sfnSize = strlen(srcFileName); + size_t sfnSize = strlen(srcFileName); size_t suffixSize; + const char* const suffixPtr = strrchr(srcFileName, '.'); if (suffixPtr == NULL) { - DISPLAYLEVEL(1, "zstd: %s: unknown suffix -- ignored \n", - srcFileName); + DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n", + srcFileName, SUFFIX_LIST); return NULL; } suffixSize = strlen(suffixPtr); /* check suffix is authorized */ if (sfnSize <= suffixSize - || ( strcmp(suffixPtr, ZSTD_EXTENSION) - #ifdef ZSTD_GZDECOMPRESS - && strcmp(suffixPtr, GZ_EXTENSION) - #endif - #ifdef ZSTD_LZMADECOMPRESS - && strcmp(suffixPtr, XZ_EXTENSION) - && strcmp(suffixPtr, LZMA_EXTENSION) - #endif - #ifdef ZSTD_LZ4DECOMPRESS - && strcmp(suffixPtr, LZ4_EXTENSION) - #endif - ) ) { - const char* suffixlist = ZSTD_EXTENSION - #ifdef ZSTD_GZDECOMPRESS - "/" GZ_EXTENSION - #endif - #ifdef ZSTD_LZMADECOMPRESS - "/" XZ_EXTENSION "/" LZMA_EXTENSION - #endif - #ifdef ZSTD_LZ4DECOMPRESS - "/" LZ4_EXTENSION - #endif - ; - DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected) -- ignored \n", - srcFileName, suffixlist); + || (strstr(SUFFIX_LIST, suffixPtr) == NULL)) { + DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n", + srcFileName, SUFFIX_LIST); return NULL; } + if (outDirName) { + outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, 0); + sfnSize = strlen(outDirFilename); + assert(outDirFilename != NULL); + } - /* allocate enough space to write dstFilename into it */ if (dfnbCapacity+suffixSize <= sfnSize+1) { + /* allocate enough space to write dstFilename into it */ free(dstFileNameBuffer); dfnbCapacity = sfnSize + 20; dstFileNameBuffer = (char*)malloc(dfnbCapacity); @@@ -2210,18 -2355,13 +2346,23 @@@ /* return dst name == src name truncated from suffix */ assert(dstFileNameBuffer != NULL); + size_t dstFileNameEndPos = sfnSize - suffixSize; - memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos); + if (outDirFilename) { - memcpy(dstFileNameBuffer, outDirFilename, sfnSize - suffixSize); ++ memcpy(dstFileNameBuffer, outDirFilename, dstFileNameEndPos); + free(outDirFilename); + } else { - memcpy(dstFileNameBuffer, srcFileName, sfnSize - suffixSize); - } - dstFileNameBuffer[sfnSize-suffixSize] = '\0'; ++ memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos); ++ } + /* The short tar extensions tzst, tgz, txz and tlz4 files should have "tar" extension on decompression + * To check that the file is one of them we can check that it starts with "t" + */ + if (suffixPtr[1] == 't') { + dstFileNameBuffer[dstFileNameEndPos++] = '.'; + dstFileNameBuffer[dstFileNameEndPos++] = 't'; + dstFileNameBuffer[dstFileNameEndPos++] = 'a'; + dstFileNameBuffer[dstFileNameEndPos++] = 'r'; + } + dstFileNameBuffer[dstFileNameEndPos] = '\0'; return dstFileNameBuffer; /* note : dstFileNameBuffer memory is not going to be free */