fixed detection of input==output on Visual

due to bad support of inode identifiers.
On Visual, option is limited to same file name,
which is imperfect, but way better than disabling the feature entirely.

It's enough to pass associated tests.
This commit is contained in:
Yann Collet
2018-12-26 15:51:34 -08:00
parent ae1d6bd48e
commit 6b7a1d6127
+20 -7
View File
@@ -423,16 +423,29 @@ static FILE* FIO_openDstFile(const char* srcFileName, const char* dstFileName)
return stdout; return stdout;
} }
/* ensure dst is not the same file as src */
if (srcFileName != NULL) { if (srcFileName != NULL) {
stat_t srcStat; #ifdef _MSC_VER
stat_t dstStat; /* note : Visual does not support file identification by inode.
if ( UTIL_getFileStat(srcFileName, &srcStat) * The following work-around is limited to detecting exact name repetition only,
&& UTIL_getFileStat(dstFileName, &dstStat) ) { * aka `filename` is considered different from `subdir/../filename` */
if ( srcStat.st_dev == dstStat.st_dev if (!strcmp(srcFileName, dstFileName)) {
&& srcStat.st_ino == dstStat.st_ino ) {
DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n"); DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n");
return NULL; return NULL;
} } } }
#else
stat_t srcStat;
stat_t dstStat;
if (UTIL_getFileStat(srcFileName, &srcStat)
&& UTIL_getFileStat(dstFileName, &dstStat)) {
if (srcStat.st_dev == dstStat.st_dev
&& srcStat.st_ino == dstStat.st_ino) {
DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n");
return NULL;
}
}
#endif
}
if (g_sparseFileSupport == 1) { if (g_sparseFileSupport == 1) {
g_sparseFileSupport = ZSTD_SPARSE_DEFAULT; g_sparseFileSupport = ZSTD_SPARSE_DEFAULT;