@@ -823,41 +823,62 @@ static void FIO_adjustMemLimitForPatchFromMode(FIO_prefs_t* const prefs,
823823 FIO_setMemLimit (prefs , (unsigned )maxSize );
824824}
825825
826- /* FIO_removeMultiFilesWarning() :
826+ /* FIO_multiFilesConcatWarning() :
827+ * This function handles logic when processing multiple files with -o or -c, displaying the appropriate warnings/prompts.
827828 * Returns 1 if the console should abort, 0 if console should proceed.
828- * This function handles logic when processing multiple files with -o, displaying the appropriate warnings/prompts.
829829 *
830- * If -f is specified, or there is just 1 file, zstd will always proceed as usual.
831- * If --rm is specified, there will be a prompt asking for user confirmation.
832- * If -f is specified with --rm, zstd will proceed as usual
833- * If -q is specified with --rm, zstd will abort pre-emptively
834- * If neither flag is specified, zstd will prompt the user for confirmation to proceed.
835- * If --rm is not specified, then zstd will print a warning to the user (which can be silenced with -q).
836- * Note : --rm in combination with stdout is not allowed.
830+ * If output is stdout or test mode is active, check or enforce `--rm` disabled.
831+ *
832+ * If there is just 1 file to process, zstd will proceed as usual.
833+ * If each file get processed into its own separate destination file, proceed as usual.
834+ *
835+ * When multiple files are processed into a single output,
836+ * display a warning message, then disable --rm if it's set.
837+ *
838+ * If -f is specified or if output is stdout, just proceed.
839+ * If output is set with -o, prompt for confirmation.
837840 */
838- static int FIO_removeMultiFilesWarning ( FIO_ctx_t * const fCtx , const FIO_prefs_t * const prefs , const char * outFileName , int displayLevelCutoff )
841+ static int FIO_multiFilesConcatWarning ( const FIO_ctx_t * fCtx , FIO_prefs_t * prefs , const char * outFileName , int displayLevelCutoff )
839842{
840- int error = 0 ;
841- if (fCtx -> nbFilesTotal > 1 && !prefs -> overwrite ) {
842- if (g_display_prefs .displayLevel <= displayLevelCutoff ) {
843- if (prefs -> removeSrcFile ) {
844- DISPLAYLEVEL (1 , "zstd: Aborting... not deleting files and processing into dst: %s\n" , outFileName );
845- error = 1 ;
846- }
847- } else {
848- if (!strcmp (outFileName , stdoutmark )) {
849- DISPLAYLEVEL (2 , "zstd: WARNING: all input files will be processed and concatenated into stdout. \n" );
850- } else {
851- DISPLAYLEVEL (2 , "zstd: WARNING: all input files will be processed and concatenated into a single output file: %s \n" , outFileName );
852- }
853- DISPLAYLEVEL (2 , "The concatenated output CANNOT regenerate original file names nor directory structure. \n" )
854- if (prefs -> removeSrcFile ) {
855- assert (fCtx -> hasStdoutOutput == 0 ); /* not possible : never erase source files when output == stdout */
856- error = (g_display_prefs .displayLevel > displayLevelCutoff ) && UTIL_requireUserConfirmation ("This is a destructive operation. Proceed? (y/n): " , "Aborting..." , "yY" , fCtx -> hasStdinInput );
857- }
858- }
843+ if (fCtx -> hasStdoutOutput ) assert (prefs -> removeSrcFile == 0 );
844+ if (prefs -> testMode ) {
845+ prefs -> removeSrcFile = 0 ; /* enforce */
846+ return 0 ;
859847 }
860- return error ;
848+
849+ if (fCtx -> nbFilesTotal == 1 ) return 0 ;
850+ assert (fCtx -> nbFilesTotal > 1 );
851+
852+ if (!outFileName ) return 0 ;
853+
854+ if (fCtx -> hasStdoutOutput ) {
855+ DISPLAYLEVEL (2 , "zstd: WARNING: all input files will be processed and concatenated into stdout. \n" );
856+ } else {
857+ DISPLAYLEVEL (2 , "zstd: WARNING: all input files will be processed and concatenated into a single output file: %s \n" , outFileName );
858+ }
859+ DISPLAYLEVEL (2 , "The concatenated output CANNOT regenerate original file names nor directory structure. \n" )
860+
861+ /* multi-input into single output : --rm is not allowed */
862+ if (prefs -> removeSrcFile ) {
863+ DISPLAYLEVEL (2 , "Since it's a destructive operation, input files will not be removed. \n" );
864+ prefs -> removeSrcFile = 0 ;
865+ }
866+
867+ if (fCtx -> hasStdoutOutput ) return 0 ;
868+ if (prefs -> overwrite ) return 0 ;
869+
870+ /* multiple files concatenated into single destination file using -o without -f */
871+ DISPLAY ("multiple files concatenated into single destination file using -o without -f \n" );
872+ DISPLAY ("g_display_prefs.displayLevel = %i \n" , g_display_prefs .displayLevel );
873+ DISPLAY ("displayLevelCutoff = %i \n" , displayLevelCutoff );
874+ if (g_display_prefs .displayLevel <= displayLevelCutoff ) {
875+ /* quiet mode => no prompt => fail automatically */
876+ DISPLAYLEVEL (1 , "Concatenating multiple processed inputs into a single output loses file metadata. \n" );
877+ DISPLAYLEVEL (1 , "Aborting. \n" );
878+ return 1 ;
879+ }
880+ /* normal mode => prompt */
881+ return UTIL_requireUserConfirmation ("Proceed? (y/n): " , "Aborting..." , "yY" , fCtx -> hasStdinInput );
861882}
862883
863884static ZSTD_inBuffer setInBuffer (const void * buf , size_t s , size_t pos )
@@ -1767,9 +1788,9 @@ FIO_compressFilename_srcFile(FIO_ctx_t* const fCtx,
17671788 & srcFileStat , compressionLevel );
17681789 AIO_ReadPool_closeFile (ress .readCtx );
17691790
1770- if ( prefs -> removeSrcFile /* --rm */
1771- && result == 0 /* success */
1772- && strcmp (srcFileName , stdinmark ) /* exception : don't erase stdin */
1791+ if ( prefs -> removeSrcFile /* --rm */
1792+ && result == 0 /* success */
1793+ && strcmp (srcFileName , stdinmark ) /* exception : don't erase stdin */
17731794 ) {
17741795 /* We must clear the handler, since after this point calling it would
17751796 * delete both the source and destination files.
@@ -1920,7 +1941,7 @@ int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
19201941 assert (outFileName != NULL || suffix != NULL );
19211942 if (outFileName != NULL ) { /* output into a single destination (stdout typically) */
19221943 FILE * dstFile ;
1923- if (FIO_removeMultiFilesWarning (fCtx , prefs , outFileName , 1 /* displayLevelCutoff */ )) {
1944+ if (FIO_multiFilesConcatWarning (fCtx , prefs , outFileName , 1 /* displayLevelCutoff */ )) {
19241945 FIO_freeCResources (& ress );
19251946 return 1 ;
19261947 }
@@ -2742,7 +2763,7 @@ FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
27422763 dRess_t ress = FIO_createDResources (prefs , dictFileName );
27432764
27442765 if (outFileName ) {
2745- if (FIO_removeMultiFilesWarning (fCtx , prefs , outFileName , 1 /* displayLevelCutoff */ )) {
2766+ if (FIO_multiFilesConcatWarning (fCtx , prefs , outFileName , 1 /* displayLevelCutoff */ )) {
27462767 FIO_freeDResources (ress );
27472768 return 1 ;
27482769 }
0 commit comments