refactor : --rm is ignored with stdout
`zstd` CLI has progressively moved to the policy of ignoring `--rm` command when the output is `stdout`. The primary drive is to feature a behavior more consistent with `gzip`, when `--rm` is the default, but is also ignored when output is `stdout`. Other policies are certainly possible, but would break from this `gzip` convention. The new policy was inconsistenly enforced, depending on the exact list of commands. For example, it was possible to circumvent it by using `-c --rm` in this order, which would re-establish source removal. - Update the CLI so that it necessarily catch these situations and ensure that `--rm` is always disabled when output is `stdout`. - Added a warning message in this case (for verbosity 3 `-v`). - Added an `assert()`, which controls that `--rm` is no longer active with `stdout` - Added tests, which control the behavior, even when `--rm` is added after `-c` - Removed some legacy code which where trying to apply a specific policy for the `stdout` + `--rm` case, which is no longer possible
This commit is contained in:
+5
-9
@@ -362,7 +362,7 @@ void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag) { prefs->dictID
|
||||
|
||||
void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag) { prefs->checksumFlag = checksumFlag; }
|
||||
|
||||
void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag) { prefs->removeSrcFile = (flag>0); }
|
||||
void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, int flag) { prefs->removeSrcFile = (flag!=0); }
|
||||
|
||||
void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit) { prefs->memLimit = memLimit; }
|
||||
|
||||
@@ -833,7 +833,7 @@ static void FIO_adjustMemLimitForPatchFromMode(FIO_prefs_t* const prefs,
|
||||
* If -q is specified with --rm, zstd will abort pre-emptively
|
||||
* If neither flag is specified, zstd will prompt the user for confirmation to proceed.
|
||||
* If --rm is not specified, then zstd will print a warning to the user (which can be silenced with -q).
|
||||
* However, if the output is stdout, we will always abort rather than displaying the warning prompt.
|
||||
* Note : --rm in combination with stdout is not allowed.
|
||||
*/
|
||||
static int FIO_removeMultiFilesWarning(FIO_ctx_t* const fCtx, const FIO_prefs_t* const prefs, const char* outFileName, int displayLevelCutoff)
|
||||
{
|
||||
@@ -850,14 +850,10 @@ static int FIO_removeMultiFilesWarning(FIO_ctx_t* const fCtx, const FIO_prefs_t*
|
||||
} else {
|
||||
DISPLAYLEVEL(2, "zstd: WARNING: all input files will be processed and concatenated into a single output file: %s \n", outFileName);
|
||||
}
|
||||
DISPLAYLEVEL(2, "The concatenated output CANNOT regenerate the original directory tree. \n")
|
||||
DISPLAYLEVEL(2, "The concatenated output CANNOT regenerate original file names nor directory structure. \n")
|
||||
if (prefs->removeSrcFile) {
|
||||
if (fCtx->hasStdoutOutput) {
|
||||
DISPLAYLEVEL(1, "Aborting. Use -f if you really want to delete the files and output to stdout\n");
|
||||
error = 1;
|
||||
} else {
|
||||
error = g_display_prefs.displayLevel > displayLevelCutoff && UTIL_requireUserConfirmation("This is a destructive operation. Proceed? (y/n): ", "Aborting...", "yY", fCtx->hasStdinInput);
|
||||
}
|
||||
assert(fCtx->hasStdoutOutput == 0); /* not possible : never erase source files when output == stdout */
|
||||
error = (g_display_prefs.displayLevel > displayLevelCutoff) && UTIL_requireUserConfirmation("This is a destructive operation. Proceed? (y/n): ", "Aborting...", "yY", fCtx->hasStdinInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user