@@ -585,8 +585,6 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
585
585
const char * srcFileName , const char * dstFileName ,
586
586
const int mode )
587
587
{
588
- int isDstRegFile ;
589
-
590
588
if (prefs -> testMode ) return NULL ; /* do not open file in test mode */
591
589
592
590
assert (dstFileName != NULL );
@@ -606,16 +604,7 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
606
604
return NULL ;
607
605
}
608
606
609
- isDstRegFile = UTIL_isRegularFile (dstFileName ); /* invoke once */
610
- if (prefs -> sparseFileSupport == 1 ) {
611
- prefs -> sparseFileSupport = ZSTD_SPARSE_DEFAULT ;
612
- if (!isDstRegFile ) {
613
- prefs -> sparseFileSupport = 0 ;
614
- DISPLAYLEVEL (4 , "Sparse File Support is disabled when output is not a file \n" );
615
- }
616
- }
617
-
618
- if (isDstRegFile ) {
607
+ if (UTIL_isRegularFile (dstFileName )) {
619
608
/* Check if destination file already exists */
620
609
#if !defined(_WIN32 )
621
610
/* this test does not work on Windows :
@@ -641,6 +630,7 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
641
630
}
642
631
643
632
{
633
+ int isDstRegFile ;
644
634
#if defined(_WIN32 )
645
635
/* Windows requires opening the file as a "binary" file to avoid
646
636
* mangling. This macro doesn't exist on unix. */
@@ -658,6 +648,17 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
658
648
f = fdopen (fd , "wb" );
659
649
}
660
650
#endif
651
+
652
+ /* Check regular file after opening with O_CREAT */
653
+ isDstRegFile = UTIL_isFdRegularFile (fd );
654
+ if (prefs -> sparseFileSupport == 1 ) {
655
+ prefs -> sparseFileSupport = ZSTD_SPARSE_DEFAULT ;
656
+ if (!isDstRegFile ) {
657
+ prefs -> sparseFileSupport = 0 ;
658
+ DISPLAYLEVEL (4 , "Sparse File Support is disabled when output is not a file \n" );
659
+ }
660
+ }
661
+
661
662
if (f == NULL ) {
662
663
if (UTIL_isFileDescriptorPipe (dstFileName )) {
663
664
DISPLAYLEVEL (1 , "zstd: error: no output specified (use -o or -c). \n" );
0 commit comments