Fix Build; Refactor
This commit is contained in:
parent
30b27ee0c9
commit
91c3f545cc
@ -1496,17 +1496,17 @@ FIO_determineCompressedName(const char* srcFileName, const char* outDirName, con
|
|||||||
static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
|
static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
|
||||||
char* outDirFilename = NULL;
|
char* outDirFilename = NULL;
|
||||||
size_t sfnSize = strlen(srcFileName);
|
size_t sfnSize = strlen(srcFileName);
|
||||||
size_t const suffixSize = strlen(suffix);
|
size_t const srcSuffixLen = strlen(suffix);
|
||||||
if (outDirName) {
|
if (outDirName) {
|
||||||
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, suffixSize);
|
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, srcSuffixLen);
|
||||||
sfnSize = strlen(outDirFilename);
|
sfnSize = strlen(outDirFilename);
|
||||||
assert(outDirFilename != NULL);
|
assert(outDirFilename != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dfnbCapacity <= sfnSize+suffixSize+1) {
|
if (dfnbCapacity <= sfnSize+srcSuffixLen+1) {
|
||||||
/* resize buffer for dstName */
|
/* resize buffer for dstName */
|
||||||
free(dstFileNameBuffer);
|
free(dstFileNameBuffer);
|
||||||
dfnbCapacity = sfnSize + suffixSize + 30;
|
dfnbCapacity = sfnSize + srcSuffixLen + 30;
|
||||||
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
||||||
if (!dstFileNameBuffer) {
|
if (!dstFileNameBuffer) {
|
||||||
EXM_THROW(30, "zstd: %s", strerror(errno));
|
EXM_THROW(30, "zstd: %s", strerror(errno));
|
||||||
@ -1520,7 +1520,7 @@ FIO_determineCompressedName(const char* srcFileName, const char* outDirName, con
|
|||||||
} else {
|
} else {
|
||||||
memcpy(dstFileNameBuffer, srcFileName, sfnSize);
|
memcpy(dstFileNameBuffer, srcFileName, sfnSize);
|
||||||
}
|
}
|
||||||
memcpy(dstFileNameBuffer+sfnSize, suffix, suffixSize+1 /* Include terminating null */);
|
memcpy(dstFileNameBuffer+sfnSize, suffix, srcSuffixLen+1 /* Include terminating null */);
|
||||||
return dstFileNameBuffer;
|
return dstFileNameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2287,6 +2287,37 @@ int FIO_decompressFilename(FIO_prefs_t* const prefs,
|
|||||||
return decodingError;
|
return decodingError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *suffixList[] = {
|
||||||
|
ZSTD_EXTENSION,
|
||||||
|
TZSTD_EXTENSION,
|
||||||
|
#ifdef ZSTD_GZDECOMPRESS
|
||||||
|
GZ_EXTENSION,
|
||||||
|
TGZ_EXTENSION,
|
||||||
|
#endif
|
||||||
|
#ifdef ZSTD_LZMADECOMPRESS
|
||||||
|
LZMA_EXTENSION,
|
||||||
|
XZ_EXTENSION,
|
||||||
|
TXZ_EXTENSION,
|
||||||
|
#endif
|
||||||
|
#ifdef ZSTD_LZ4DECOMPRESS
|
||||||
|
LZ4_EXTENSION,
|
||||||
|
TLZ4_EXTENSION,
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *suffixListStr =
|
||||||
|
ZSTD_EXTENSION "/" TZSTD_EXTENSION
|
||||||
|
#ifdef ZSTD_GZDECOMPRESS
|
||||||
|
"/" GZ_EXTENSION "/" TGZ_EXTENSION
|
||||||
|
#endif
|
||||||
|
#ifdef ZSTD_LZMADECOMPRESS
|
||||||
|
"/" LZMA_EXTENSION "/" XZ_EXTENSION "/" TXZ_EXTENSION
|
||||||
|
#endif
|
||||||
|
#ifdef ZSTD_LZ4DECOMPRESS
|
||||||
|
"/" LZ4_EXTENSION "/" TLZ4_EXTENSION
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
/* FIO_determineDstName() :
|
/* FIO_determineDstName() :
|
||||||
* create a destination filename from a srcFileName.
|
* create a destination filename from a srcFileName.
|
||||||
@ -2297,72 +2328,79 @@ FIO_determineDstName(const char* srcFileName, const char* outDirName)
|
|||||||
{
|
{
|
||||||
static size_t dfnbCapacity = 0;
|
static size_t dfnbCapacity = 0;
|
||||||
static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
|
static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
|
||||||
|
size_t dstFileNameEndPos;
|
||||||
char* outDirFilename = NULL;
|
char* outDirFilename = NULL;
|
||||||
|
const char* dstSuffix = "";
|
||||||
const char* SUFFIX_LIST = ZSTD_EXTENSION "/" TZSTD_EXTENSION
|
size_t dstSuffixLen = 0;
|
||||||
#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 sfnSize = strlen(srcFileName);
|
size_t sfnSize = strlen(srcFileName);
|
||||||
size_t suffixSize;
|
|
||||||
|
|
||||||
const char* const suffixPtr = strrchr(srcFileName, '.');
|
size_t srcSuffixLen;
|
||||||
if (suffixPtr == NULL) {
|
const char* const srcSuffix = strrchr(srcFileName, '.');
|
||||||
DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n",
|
if (srcSuffix == NULL) {
|
||||||
srcFileName, SUFFIX_LIST);
|
DISPLAYLEVEL(1,
|
||||||
|
"zstd: %s: unknown suffix (%s expected). "
|
||||||
|
"Can't derive the output file name. "
|
||||||
|
"Specify it with -o dstFileName. Ignoring.\n",
|
||||||
|
srcFileName, suffixListStr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
suffixSize = strlen(suffixPtr);
|
srcSuffixLen = strlen(srcSuffix);
|
||||||
|
|
||||||
/* check suffix is authorized */
|
{
|
||||||
if (sfnSize <= suffixSize
|
const char** matchedSuffixPtr;
|
||||||
|| (strstr(SUFFIX_LIST, suffixPtr) == NULL)) {
|
for (matchedSuffixPtr = suffixList; *matchedSuffixPtr != NULL; matchedSuffixPtr++) {
|
||||||
DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n",
|
if (!strcmp(*matchedSuffixPtr, srcSuffix)) {
|
||||||
srcFileName, SUFFIX_LIST);
|
break;
|
||||||
return NULL;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check suffix is authorized */
|
||||||
|
if (sfnSize <= srcSuffixLen || *matchedSuffixPtr == NULL) {
|
||||||
|
DISPLAYLEVEL(1,
|
||||||
|
"zstd: %s: unknown suffix (%s expected). "
|
||||||
|
"Can't derive the output file name. "
|
||||||
|
"Specify it with -o dstFileName. Ignoring.\n",
|
||||||
|
srcFileName, suffixListStr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*matchedSuffixPtr)[1] == 't') {
|
||||||
|
dstSuffix = ".tar";
|
||||||
|
dstSuffixLen = strlen(dstSuffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outDirName) {
|
if (outDirName) {
|
||||||
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, 0);
|
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, 0);
|
||||||
sfnSize = strlen(outDirFilename);
|
sfnSize = strlen(outDirFilename);
|
||||||
assert(outDirFilename != NULL);
|
assert(outDirFilename != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dfnbCapacity+suffixSize <= sfnSize+1) {
|
if (dfnbCapacity+srcSuffixLen <= sfnSize+1+dstSuffixLen) {
|
||||||
/* allocate enough space to write dstFilename into it */
|
/* allocate enough space to write dstFilename into it */
|
||||||
free(dstFileNameBuffer);
|
free(dstFileNameBuffer);
|
||||||
dfnbCapacity = sfnSize + 20;
|
dfnbCapacity = sfnSize + 20;
|
||||||
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
||||||
if (dstFileNameBuffer==NULL)
|
if (dstFileNameBuffer==NULL)
|
||||||
EXM_THROW(74, "%s : not enough memory for dstFileName", strerror(errno));
|
EXM_THROW(74, "%s : not enough memory for dstFileName",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return dst name == src name truncated from suffix */
|
/* return dst name == src name truncated from suffix */
|
||||||
assert(dstFileNameBuffer != NULL);
|
assert(dstFileNameBuffer != NULL);
|
||||||
size_t dstFileNameEndPos = sfnSize - suffixSize;
|
dstFileNameEndPos = sfnSize - srcSuffixLen;
|
||||||
if (outDirFilename) {
|
if (outDirFilename) {
|
||||||
memcpy(dstFileNameBuffer, outDirFilename, dstFileNameEndPos);
|
memcpy(dstFileNameBuffer, outDirFilename, dstFileNameEndPos);
|
||||||
free(outDirFilename);
|
free(outDirFilename);
|
||||||
} else {
|
} else {
|
||||||
memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos);
|
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"
|
/* The short tar extensions tzst, tgz, txz and tlz4 files should have "tar"
|
||||||
*/
|
* extension on decompression. Also writes terminating null. */
|
||||||
if (suffixPtr[1] == 't') {
|
strcpy(dstFileNameBuffer + dstFileNameEndPos, dstSuffix);
|
||||||
dstFileNameBuffer[dstFileNameEndPos++] = '.';
|
dstFileNameEndPos += dstSuffixLen;
|
||||||
dstFileNameBuffer[dstFileNameEndPos++] = 't';
|
|
||||||
dstFileNameBuffer[dstFileNameEndPos++] = 'a';
|
|
||||||
dstFileNameBuffer[dstFileNameEndPos++] = 'r';
|
|
||||||
}
|
|
||||||
dstFileNameBuffer[dstFileNameEndPos] = '\0';
|
|
||||||
return dstFileNameBuffer;
|
return dstFileNameBuffer;
|
||||||
|
|
||||||
/* note : dstFileNameBuffer memory is not going to be free */
|
/* note : dstFileNameBuffer memory is not going to be free */
|
||||||
|
@ -30,15 +30,22 @@ extern "C" {
|
|||||||
#else
|
#else
|
||||||
# define nulmark "/dev/null"
|
# define nulmark "/dev/null"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* We test whether the extension we found starts with 't', and if so, we append
|
||||||
|
* ".tar" to the end of the output name.
|
||||||
|
*/
|
||||||
#define LZMA_EXTENSION ".lzma"
|
#define LZMA_EXTENSION ".lzma"
|
||||||
#define XZ_EXTENSION ".xz"
|
#define XZ_EXTENSION ".xz"
|
||||||
#define TXZ_EXTENSION ".txz"
|
#define TXZ_EXTENSION ".txz"
|
||||||
|
|
||||||
#define GZ_EXTENSION ".gz"
|
#define GZ_EXTENSION ".gz"
|
||||||
#define TGZ_EXTENSION ".tgz"
|
#define TGZ_EXTENSION ".tgz"
|
||||||
|
|
||||||
#define ZSTD_EXTENSION ".zst"
|
#define ZSTD_EXTENSION ".zst"
|
||||||
#define TZSTD_EXTENSION ".tzst"
|
#define TZSTD_EXTENSION ".tzst"
|
||||||
|
|
||||||
#define LZ4_EXTENSION ".lz4"
|
#define LZ4_EXTENSION ".lz4"
|
||||||
#define TLZ4_EXTENSION ".tlz4"
|
#define TLZ4_EXTENSION ".tlz4"
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user