mirror of
https://github.com/facebook/zstd.git
synced 2025-10-07 00:12:40 -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;
|
||||
}
|
||||
|
||||
/* check if src file is the same as dst */
|
||||
/* ensure dst is not the same as src */
|
||||
if (srcFileName != NULL && UTIL_isSameFile(srcFileName, dstFileName)) {
|
||||
DISPLAYLEVEL(1, "zstd: Refusing to open an output file which will overwrite the input file \n");
|
||||
return NULL;
|
||||
@ -610,6 +610,7 @@ typedef struct {
|
||||
size_t srcBufferSize;
|
||||
void* dstBuffer;
|
||||
size_t dstBufferSize;
|
||||
const char* dictFileName;
|
||||
ZSTD_CStream* cctx;
|
||||
} 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 */
|
||||
if (dictFileName && (dictBuffer==NULL))
|
||||
EXM_THROW(32, "allocation error : can't create dictBuffer");
|
||||
ress.dictFileName = dictFileName;
|
||||
|
||||
if (prefs->adaptiveMode && !prefs->ldmFlag && !comprParams.windowLog)
|
||||
comprParams.windowLog = ADAPT_WINDOWLOG_DEFAULT;
|
||||
@ -1290,12 +1292,18 @@ FIO_compressFilename_srcFile(FIO_prefs_t* const prefs,
|
||||
{
|
||||
int result;
|
||||
|
||||
/* File check */
|
||||
/* ensure src is not a directory */
|
||||
if (UTIL_isDirectory(srcFileName)) {
|
||||
DISPLAYLEVEL(1, "zstd: %s is a directory -- ignored \n", srcFileName);
|
||||
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);
|
||||
if (ress.srcFile == NULL) return 1; /* srcFile could not be opened */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user