mirror of
https://github.com/facebook/zstd.git
synced 2025-10-10 00:03:36 -04:00
Implement file check
This commit is contained in:
parent
e5811e5520
commit
1290933d19
@ -515,7 +515,7 @@ static FILE* FIO_openDstFile(FIO_prefs_t* const prefs, const char* srcFileName,
|
|||||||
return stdout;
|
return stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if src file is the same as dst */
|
/* ensure dst is not the same as src */
|
||||||
if (srcFileName != NULL && UTIL_isSameFile(srcFileName, dstFileName)) {
|
if (srcFileName != NULL && UTIL_isSameFile(srcFileName, dstFileName)) {
|
||||||
DISPLAYLEVEL(1, "zstd: Refusing to open an output file which will overwrite the input file \n");
|
DISPLAYLEVEL(1, "zstd: Refusing to open an output file which will overwrite the input file \n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -610,6 +610,7 @@ typedef struct {
|
|||||||
size_t srcBufferSize;
|
size_t srcBufferSize;
|
||||||
void* dstBuffer;
|
void* dstBuffer;
|
||||||
size_t dstBufferSize;
|
size_t dstBufferSize;
|
||||||
|
const char* dictFileName;
|
||||||
ZSTD_CStream* cctx;
|
ZSTD_CStream* cctx;
|
||||||
} cRess_t;
|
} cRess_t;
|
||||||
|
|
||||||
@ -637,6 +638,7 @@ static cRess_t FIO_createCResources(FIO_prefs_t* const prefs,
|
|||||||
size_t const dictBuffSize = FIO_createDictBuffer(&dictBuffer, dictFileName); /* works with dictFileName==NULL */
|
size_t const dictBuffSize = FIO_createDictBuffer(&dictBuffer, dictFileName); /* works with dictFileName==NULL */
|
||||||
if (dictFileName && (dictBuffer==NULL))
|
if (dictFileName && (dictBuffer==NULL))
|
||||||
EXM_THROW(32, "allocation error : can't create dictBuffer");
|
EXM_THROW(32, "allocation error : can't create dictBuffer");
|
||||||
|
ress.dictFileName = dictFileName;
|
||||||
|
|
||||||
if (prefs->adaptiveMode && !prefs->ldmFlag && !comprParams.windowLog)
|
if (prefs->adaptiveMode && !prefs->ldmFlag && !comprParams.windowLog)
|
||||||
comprParams.windowLog = ADAPT_WINDOWLOG_DEFAULT;
|
comprParams.windowLog = ADAPT_WINDOWLOG_DEFAULT;
|
||||||
@ -1290,12 +1292,18 @@ FIO_compressFilename_srcFile(FIO_prefs_t* const prefs,
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* File check */
|
/* ensure src is not a directory */
|
||||||
if (UTIL_isDirectory(srcFileName)) {
|
if (UTIL_isDirectory(srcFileName)) {
|
||||||
DISPLAYLEVEL(1, "zstd: %s is a directory -- ignored \n", srcFileName);
|
DISPLAYLEVEL(1, "zstd: %s is a directory -- ignored \n", srcFileName);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ensure src is not the same as dict */
|
||||||
|
if (UTIL_isSameFile(srcFileName, ress.dictFileName)) {
|
||||||
|
DISPLAYLEVEL(1, "zstd: Refusing to use %s as an input file and dictionary \n", srcFileName);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
ress.srcFile = FIO_openSrcFile(srcFileName);
|
ress.srcFile = FIO_openSrcFile(srcFileName);
|
||||||
if (ress.srcFile == NULL) return 1; /* srcFile could not be opened */
|
if (ress.srcFile == NULL) return 1; /* srcFile could not be opened */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user