return NULL;
}
DISPLAY("zstd: %s already exists; ", dstFileName);
- if (UTIL_requireUserConfirmationToProceed("overwrite (y/n) ? ", "Not overwritten \n", "yY"))
+ if (UTIL_requireUserConfirmation("overwrite (y/n) ? ", "Not overwritten \n", "yY"))
return NULL;
}
/* need to unlink */
FIO_setMemLimit(prefs, (unsigned)maxSize);
}
+/* FIO_removeMultiFilesWarning() :
+ * Returns 1 if the console should abort, 0 if console should proceed.
+ * Based on displayLevelCutoff (typically == 1) and the global setting g_display_prefs.displayLevel, this
+ * function may print a warning message, a user prompt, both, or none.
+ */
+static int FIO_removeMultiFilesWarning(const FIO_prefs_t* const prefs, int displayLevelCutoff, const char* outFileName)
+{
+ int error;
+ error = 0;
+ if (prefs->nbFiles > 1 && !prefs->overwrite) {
+ if (g_display_prefs.displayLevel <= displayLevelCutoff) {
+ if (prefs->removeSrcFile) {
+ DISPLAYLEVEL(1, "zstd: Aborting... not deleting files and processing into dst: %s", outFileName);
+ error = 1;
+ }
+ } else {
+ if (!strcmp(outFileName, stdoutmark)) {
+ DISPLAYLEVEL(2, "zstd: WARNING: all input files will be processed and concatenated into stdout. ");
+ } else {
+ DISPLAYLEVEL(2, "zstd: WARNING: all input files will be processed and concatenated into a single output file: %s ", outFileName);
+ }
+ if (prefs->removeSrcFile)
+ error = g_display_prefs.displayLevel > displayLevelCutoff && UTIL_requireUserConfirmation("Proceed? (y/n): ", "Aborting...", "yY");
+ DISPLAY("\n");
+ }
+ }
+ return error;
+}
+
#ifndef ZSTD_NOCOMPRESS
/* **********************************************************************
/* init */
assert(outFileName != NULL || suffix != NULL);
if (outFileName != NULL) { /* output into a single destination (stdout typically) */
- if (nbFiles > 1 && !prefs->overwrite) {
- /* g_display_prefs.displayLevel <= 1 corresponds to -q flag */
- DISPLAY("%d\n", g_display_prefs.displayLevel);
- if (g_display_prefs.displayLevel <= 1) {
- if (prefs->removeSrcFile) {
- DISPLAY("zstd: Aborting... not deleting files and processing into dst: %s", outFileName);
- return 1;
- }
- } else {
- if (!strcmp (outFileName, stdoutmark)) {
- DISPLAY("zstd: WARNING: all input files will be processed and concatenated into stdout. ");
- } else {
- DISPLAY("zstd: WARNING: all input files will be processed and concatenated into a single output file: %s ", outFileName);
- }
- if (prefs->removeSrcFile)
- error = g_display_prefs.displayLevel > 1 && UTIL_requireUserConfirmationToProceed("Proceed? (y/n): ", "Aborting...", "yY");
- DISPLAY("\n");
- }
- }
+ if (FIO_removeMultiFilesWarning(prefs, 1 /* displayLevelCutoff */, outFileName))
+ return 1;
ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName);
if (ress.dstFile == NULL) { /* could not open outFileName */
error = 1;
dRess_t ress = FIO_createDResources(prefs, dictFileName);
if (outFileName) {
+ if (FIO_removeMultiFilesWarning(prefs, 1 /* displayLevelCutoff */, outFileName))
+ return 1;
if (!prefs->testMode) {
ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName);
if (ress.dstFile == 0) EXM_THROW(19, "cannot open %s", outFileName);
******************************************/
int g_utilDisplayLevel;
-int UTIL_requireUserConfirmationToProceed(const char* prompt, const char* abortMsg,
+int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg,
const char* acceptableLetters) {
- int ch;
+ int ch, result;
UTIL_DISPLAY("%s", prompt);
ch = getchar();
+ result = 0;
if (strchr(acceptableLetters, ch) == NULL) {
UTIL_DISPLAY("%s", abortMsg);
- return 1;
+ result = 1;
}
/* flush the rest */
while ((ch!=EOF) && (ch!='\n'))
ch = getchar();
-
- return 0;
+ return result;
}