Merge pull request #4353 from afq984/sparse
Check regular file for sparse support after opening
This commit is contained in:
+13
-12
@@ -585,8 +585,6 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
|||||||
const char* srcFileName, const char* dstFileName,
|
const char* srcFileName, const char* dstFileName,
|
||||||
const int mode)
|
const int mode)
|
||||||
{
|
{
|
||||||
int isDstRegFile;
|
|
||||||
|
|
||||||
if (prefs->testMode) return NULL; /* do not open file in test mode */
|
if (prefs->testMode) return NULL; /* do not open file in test mode */
|
||||||
|
|
||||||
assert(dstFileName != NULL);
|
assert(dstFileName != NULL);
|
||||||
@@ -606,16 +604,7 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDstRegFile = UTIL_isRegularFile(dstFileName); /* invoke once */
|
if (UTIL_isRegularFile(dstFileName)) {
|
||||||
if (prefs->sparseFileSupport == 1) {
|
|
||||||
prefs->sparseFileSupport = ZSTD_SPARSE_DEFAULT;
|
|
||||||
if (!isDstRegFile) {
|
|
||||||
prefs->sparseFileSupport = 0;
|
|
||||||
DISPLAYLEVEL(4, "Sparse File Support is disabled when output is not a file \n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDstRegFile) {
|
|
||||||
/* Check if destination file already exists */
|
/* Check if destination file already exists */
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
/* this test does not work on Windows :
|
/* this test does not work on Windows :
|
||||||
@@ -641,6 +630,7 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
int isDstRegFile;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
/* Windows requires opening the file as a "binary" file to avoid
|
/* Windows requires opening the file as a "binary" file to avoid
|
||||||
* mangling. This macro doesn't exist on unix. */
|
* mangling. This macro doesn't exist on unix. */
|
||||||
@@ -658,6 +648,17 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
|||||||
f = fdopen(fd, "wb");
|
f = fdopen(fd, "wb");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Check regular file after opening with O_CREAT */
|
||||||
|
isDstRegFile = UTIL_isFdRegularFile(fd);
|
||||||
|
if (prefs->sparseFileSupport == 1) {
|
||||||
|
prefs->sparseFileSupport = ZSTD_SPARSE_DEFAULT;
|
||||||
|
if (!isDstRegFile) {
|
||||||
|
prefs->sparseFileSupport = 0;
|
||||||
|
DISPLAYLEVEL(4, "Sparse File Support is disabled when output is not a file \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
if (UTIL_isFileDescriptorPipe(dstFileName)) {
|
if (UTIL_isFileDescriptorPipe(dstFileName)) {
|
||||||
DISPLAYLEVEL(1, "zstd: error: no output specified (use -o or -c). \n");
|
DISPLAYLEVEL(1, "zstd: error: no output specified (use -o or -c). \n");
|
||||||
|
|||||||
@@ -197,6 +197,16 @@ int UTIL_stat(const char* filename, stat_t* statbuf)
|
|||||||
return UTIL_fstat(-1, filename, statbuf);
|
return UTIL_fstat(-1, filename, statbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UTIL_isFdRegularFile(int fd)
|
||||||
|
{
|
||||||
|
stat_t statbuf;
|
||||||
|
int ret;
|
||||||
|
UTIL_TRACE_CALL("UTIL_isFdRegularFile(%d)", fd);
|
||||||
|
ret = fd >= 0 && UTIL_fstat(fd, "", &statbuf) && UTIL_isRegularFileStat(&statbuf);
|
||||||
|
UTIL_TRACE_RET(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int UTIL_isRegularFile(const char* infilename)
|
int UTIL_isRegularFile(const char* infilename)
|
||||||
{
|
{
|
||||||
stat_t statbuf;
|
stat_t statbuf;
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ int UTIL_fchmod(const int fd, char const* filename, const stat_t* statbuf, mode_
|
|||||||
* compute the needed information.
|
* compute the needed information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int UTIL_isFdRegularFile(int fd);
|
||||||
int UTIL_isRegularFile(const char* infilename);
|
int UTIL_isRegularFile(const char* infilename);
|
||||||
int UTIL_isDirectory(const char* infilename);
|
int UTIL_isDirectory(const char* infilename);
|
||||||
int UTIL_isSameFile(const char* file1, const char* file2);
|
int UTIL_isSameFile(const char* file1, const char* file2);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ Trace:FileStat: > UTIL_isRegularFile(out/file.zst)
|
|||||||
Trace:FileStat: > UTIL_stat(-1, out/file.zst)
|
Trace:FileStat: > UTIL_stat(-1, out/file.zst)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
|
Trace:FileStat: > UTIL_isFdRegularFile(-1)
|
||||||
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: > UTIL_isFileDescriptorPipe(out/file.zst)
|
Trace:FileStat: > UTIL_isFileDescriptorPipe(out/file.zst)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
zstd: out/file.zst: Permission denied
|
zstd: out/file.zst: Permission denied
|
||||||
|
|||||||
+4
@@ -22,6 +22,10 @@ Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
|||||||
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
|
Trace:FileStat: > UTIL_isFdRegularFile(*)
|
||||||
|
Trace:FileStat: > UTIL_stat(*, )
|
||||||
|
Trace:FileStat: < 1
|
||||||
|
Trace:FileStat: < 1
|
||||||
Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
||||||
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
||||||
Trace:FileStat: < 1
|
Trace:FileStat: < 1
|
||||||
+4
@@ -14,6 +14,10 @@ Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
|||||||
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
|
Trace:FileStat: > UTIL_isFdRegularFile(*)
|
||||||
|
Trace:FileStat: > UTIL_stat(*, )
|
||||||
|
Trace:FileStat: < 1
|
||||||
|
Trace:FileStat: < 1
|
||||||
Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
Trace:FileStat: > UTIL_isRegularFile(file.zst)
|
||||||
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
Trace:FileStat: > UTIL_stat(-1, file.zst)
|
||||||
Trace:FileStat: < 1
|
Trace:FileStat: < 1
|
||||||
+4
@@ -22,6 +22,10 @@ Trace:FileStat: > UTIL_isRegularFile(file)
|
|||||||
Trace:FileStat: > UTIL_stat(-1, file)
|
Trace:FileStat: > UTIL_stat(-1, file)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
|
Trace:FileStat: > UTIL_isFdRegularFile(*)
|
||||||
|
Trace:FileStat: > UTIL_stat(*, )
|
||||||
|
Trace:FileStat: < 1
|
||||||
|
Trace:FileStat: < 1
|
||||||
Trace:FileStat: > UTIL_isRegularFile(file)
|
Trace:FileStat: > UTIL_isRegularFile(file)
|
||||||
Trace:FileStat: > UTIL_stat(-1, file)
|
Trace:FileStat: > UTIL_stat(-1, file)
|
||||||
Trace:FileStat: < 1
|
Trace:FileStat: < 1
|
||||||
+4
@@ -14,6 +14,10 @@ Trace:FileStat: > UTIL_isRegularFile(file)
|
|||||||
Trace:FileStat: > UTIL_stat(-1, file)
|
Trace:FileStat: > UTIL_stat(-1, file)
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
Trace:FileStat: < 0
|
Trace:FileStat: < 0
|
||||||
|
Trace:FileStat: > UTIL_isFdRegularFile(*)
|
||||||
|
Trace:FileStat: > UTIL_stat(*, )
|
||||||
|
Trace:FileStat: < 1
|
||||||
|
Trace:FileStat: < 1
|
||||||
Trace:FileStat: > UTIL_isRegularFile(file)
|
Trace:FileStat: > UTIL_isRegularFile(file)
|
||||||
Trace:FileStat: > UTIL_stat(-1, file)
|
Trace:FileStat: > UTIL_stat(-1, file)
|
||||||
Trace:FileStat: < 1
|
Trace:FileStat: < 1
|
||||||
Reference in New Issue
Block a user