Fix --progress flag to properly control progress display and default progress display on when using -v

dev
Binh Vo 2021-06-07 11:50:22 -04:00
parent 1e17184ad0
commit d2f31b6627
2 changed files with 21 additions and 18 deletions

View File

@ -2155,6 +2155,7 @@ FIO_decompressZstdFrame(FIO_ctx_t* const fCtx, dRess_t* ress, FILE* finput,
ZSTD_inBuffer inBuff = { ress->srcBuffer, ress->srcBufferLoaded, 0 }; ZSTD_inBuffer inBuff = { ress->srcBuffer, ress->srcBufferLoaded, 0 };
ZSTD_outBuffer outBuff= { ress->dstBuffer, ress->dstBufferSize, 0 }; ZSTD_outBuffer outBuff= { ress->dstBuffer, ress->dstBufferSize, 0 };
size_t const readSizeHint = ZSTD_decompressStream(ress->dctx, &outBuff, &inBuff); size_t const readSizeHint = ZSTD_decompressStream(ress->dctx, &outBuff, &inBuff);
const int displayLevel = (!fCtx->hasStdoutOutput || g_display_prefs.progressSetting == FIO_ps_always) ? 1 : 2;
if (ZSTD_isError(readSizeHint)) { if (ZSTD_isError(readSizeHint)) {
DISPLAYLEVEL(1, "%s : Decoding error (36) : %s \n", DISPLAYLEVEL(1, "%s : Decoding error (36) : %s \n",
srcFileName, ZSTD_getErrorName(readSizeHint)); srcFileName, ZSTD_getErrorName(readSizeHint));
@ -2165,21 +2166,19 @@ FIO_decompressZstdFrame(FIO_ctx_t* const fCtx, dRess_t* ress, FILE* finput,
/* Write block */ /* Write block */
storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, outBuff.pos, prefs, storedSkips); storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, outBuff.pos, prefs, storedSkips);
frameSize += outBuff.pos; frameSize += outBuff.pos;
if (!fCtx->hasStdoutOutput || g_display_prefs.progressSetting == FIO_ps_always) { if (fCtx->nbFilesTotal > 1) {
if (fCtx->nbFilesTotal > 1) { size_t srcFileNameSize = strlen(srcFileName);
size_t srcFileNameSize = strlen(srcFileName); if (srcFileNameSize > 18) {
if (srcFileNameSize > 18) { const char* truncatedSrcFileName = srcFileName + srcFileNameSize - 15;
const char* truncatedSrcFileName = srcFileName + srcFileNameSize - 15; DISPLAYUPDATE(displayLevel, "\rDecompress: %2u/%2u files. Current: ...%s : %u MB... ",
DISPLAYUPDATE(2, "\rDecompress: %2u/%2u files. Current: ...%s : %u MB... ", fCtx->currFileIdx+1, fCtx->nbFilesTotal, truncatedSrcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
fCtx->currFileIdx+1, fCtx->nbFilesTotal, truncatedSrcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
} else {
DISPLAYUPDATE(2, "\rDecompress: %2u/%2u files. Current: %s : %u MB... ",
fCtx->currFileIdx+1, fCtx->nbFilesTotal, srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
}
} else { } else {
DISPLAYUPDATE(2, "\r%-20.20s : %u MB... ", DISPLAYUPDATE(displayLevel, "\rDecompress: %2u/%2u files. Current: %s : %u MB... ",
srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) ); fCtx->currFileIdx+1, fCtx->nbFilesTotal, srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
} }
} else {
DISPLAYUPDATE(displayLevel, "\r%-20.20s : %u MB... ",
srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
} }
if (inBuff.pos > 0) { if (inBuff.pos > 0) {
@ -2513,10 +2512,10 @@ static int FIO_decompressFrames(FIO_ctx_t* const fCtx,
fCtx->totalBytesOutput += (size_t)filesize; fCtx->totalBytesOutput += (size_t)filesize;
DISPLAYLEVEL(2, "\r%79s\r", ""); DISPLAYLEVEL(2, "\r%79s\r", "");
/* No status message in pipe mode (stdin - stdout) or multi-files mode */ /* No status message in pipe mode (stdin - stdout) or multi-files mode */
if (g_display_prefs.displayLevel >= 2) { if ((g_display_prefs.displayLevel >= 2 && fCtx->nbFilesTotal <= 1) ||
if (fCtx->nbFilesTotal <= 1 || g_display_prefs.displayLevel >= 3) { g_display_prefs.displayLevel >= 3 ||
DISPLAYLEVEL(2, "%-20s: %llu bytes \n", srcFileName, filesize); g_display_prefs.progressSetting == FIO_ps_always) {
} DISPLAYLEVEL(1, "\r%-20s: %llu bytes \n", srcFileName, filesize);
} }
return 0; return 0;

View File

@ -263,6 +263,10 @@ zstd -q -f tmpro
println "test: --no-progress flag" println "test: --no-progress flag"
zstd tmpro -c --no-progress | zstd -d -f -o "$INTOVOID" --no-progress zstd tmpro -c --no-progress | zstd -d -f -o "$INTOVOID" --no-progress
zstd tmpro -cv --no-progress | zstd -dv -f -o "$INTOVOID" --no-progress zstd tmpro -cv --no-progress | zstd -dv -f -o "$INTOVOID" --no-progress
println "test: --progress flag"
zstd tmpro -c | zstd -d -f -o "$INTOVOID" --progress 2>&1 | grep -E "[A-Za-z0-9._ ]+: [0-9]+ bytes"
zstd tmpro -c | zstd -d -f -q -o "$INTOVOID" --progress 2>&1 | grep -E "[A-Za-z0-9._ ]+: [0-9]+ bytes"
zstd tmpro -c | zstd -d -f -v -o "$INTOVOID" 2>&1 | grep -E "[A-Za-z0-9._ ]+: [0-9]+ bytes"
rm -f tmpro tmpro.zst rm -f tmpro tmpro.zst
println "test: overwrite input file (must fail)" println "test: overwrite input file (must fail)"
zstd tmp -fo tmp && die "zstd compression overwrote the input file" zstd tmp -fo tmp && die "zstd compression overwrote the input file"