Fix single file decompression summary, remove escape code dependency, add currFileIdx field to FIO_prefs, general cleanups/bugfixes
This commit is contained in:
parent
96222cd195
commit
b6abbc3ce5
@ -319,6 +319,7 @@ struct FIO_prefs_s {
|
||||
int excludeCompressedFiles;
|
||||
int patchFromMode;
|
||||
int contentSize;
|
||||
int currFileIdx;
|
||||
int nbFiles;
|
||||
};
|
||||
|
||||
@ -362,6 +363,7 @@ FIO_prefs_t* FIO_createPreferences(void)
|
||||
ret->literalCompressionMode = ZSTD_lcm_auto;
|
||||
ret->excludeCompressedFiles = 0;
|
||||
ret->nbFiles = 1;
|
||||
ret->currFileIdx = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -502,6 +504,11 @@ void FIO_setNbFiles(FIO_prefs_t* const prefs, int value)
|
||||
prefs->nbFiles = value;
|
||||
}
|
||||
|
||||
void FIO_setCurrFileIdx(FIO_prefs_t* const prefs, int value)
|
||||
{
|
||||
prefs->currFileIdx = value;
|
||||
}
|
||||
|
||||
/*-*************************************
|
||||
* Functions
|
||||
***************************************/
|
||||
@ -1268,10 +1275,15 @@ FIO_compressZstdFrame(FIO_prefs_t* const prefs,
|
||||
(unsigned)(zfp.produced >> 20),
|
||||
cShare );
|
||||
} else { /* summarized notifications if == 2; */
|
||||
DISPLAYLEVEL(2, "\033[s Read : %u ", (unsigned)(zfp.consumed >> 20));
|
||||
if (prefs->nbFiles > 1) {
|
||||
DISPLAYLEVEL(2, "\rCompressing %u/%u files. Current source: %s ", prefs->currFileIdx+1, prefs->nbFiles, srcFileName);
|
||||
} else {
|
||||
DISPLAYLEVEL(2, "\r");
|
||||
}
|
||||
DISPLAYLEVEL(2, "Read : %u ", (unsigned)(zfp.consumed >> 20));
|
||||
if (fileSize != UTIL_FILESIZE_UNKNOWN)
|
||||
DISPLAYLEVEL(2, "/ %u ", (unsigned)(fileSize >> 20));
|
||||
DISPLAYLEVEL(2, "MB ==> %2.f%%\033[u", cShare);
|
||||
DISPLAYLEVEL(2, "MB ==> %2.f%%", cShare);
|
||||
DELAY_NEXT_UPDATE();
|
||||
}
|
||||
|
||||
@ -1436,8 +1448,7 @@ FIO_compressFilename_internal(FIO_prefs_t* const prefs,
|
||||
/* Status */
|
||||
|
||||
DISPLAYLEVEL(2, "\r%79s\r", "");
|
||||
/* No status message in pipe mode (stdin - stdout) or multi-files mode */
|
||||
if (g_display_prefs.displayLevel > 2 || (prefs->nbFiles == 1 && !((!strcmp(srcFileName, stdinmark) && dstFileName && !strcmp(dstFileName,stdoutmark))))) {
|
||||
if (g_display_prefs.displayLevel > 2 || (g_display_prefs.displayLevel == 2 && prefs->nbFiles <= 1)) {
|
||||
if (readsize == 0) {
|
||||
DISPLAYLEVEL(2,"%-20s : (%6llu => %6llu bytes, %s) \n",
|
||||
srcFileName,
|
||||
@ -1673,7 +1684,7 @@ static unsigned long long FIO_getLargestFileSize(const char** inFileNames, unsig
|
||||
* or into a destination folder (specified with -O)
|
||||
*/
|
||||
int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
const char** inFileNamesTable, unsigned nbFiles,
|
||||
const char** inFileNamesTable,
|
||||
const char* outMirroredRootDirName,
|
||||
const char* outDirName,
|
||||
const char* outFileName, const char* suffix,
|
||||
@ -1682,7 +1693,7 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
{
|
||||
int error = 0;
|
||||
cRess_t ress = FIO_createCResources(prefs, dictFileName,
|
||||
FIO_getLargestFileSize(inFileNamesTable, nbFiles),
|
||||
FIO_getLargestFileSize(inFileNamesTable, prefs->nbFiles),
|
||||
compressionLevel, comprParams);
|
||||
|
||||
/* init */
|
||||
@ -1692,11 +1703,8 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
if (ress.dstFile == NULL) { /* could not open outFileName */
|
||||
error = 1;
|
||||
} else {
|
||||
unsigned u;
|
||||
for (u=0; u<nbFiles; u++) {
|
||||
if (nbFiles > 1)
|
||||
DISPLAYLEVEL(2, "\rCompressing %u/%u files. Current source: %s ", u+1, nbFiles, inFileNamesTable[u]);
|
||||
error |= FIO_compressFilename_srcFile(prefs, ress, outFileName, inFileNamesTable[u], compressionLevel);
|
||||
for (; prefs->currFileIdx < prefs->nbFiles; ++prefs->currFileIdx) {
|
||||
error |= FIO_compressFilename_srcFile(prefs, ress, outFileName, inFileNamesTable[prefs->currFileIdx], compressionLevel);
|
||||
}
|
||||
if (fclose(ress.dstFile))
|
||||
EXM_THROW(29, "Write error (%s) : cannot properly close %s",
|
||||
@ -1704,12 +1712,11 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
ress.dstFile = NULL;
|
||||
}
|
||||
} else {
|
||||
unsigned int u=0;
|
||||
if (outMirroredRootDirName)
|
||||
UTIL_mirrorSourceFilesDirectories(inFileNamesTable, nbFiles, outMirroredRootDirName);
|
||||
UTIL_mirrorSourceFilesDirectories(inFileNamesTable, prefs->nbFiles, outMirroredRootDirName);
|
||||
|
||||
for (u=0; u<nbFiles; u++) {
|
||||
const char* const srcFileName = inFileNamesTable[u];
|
||||
for (; prefs->currFileIdx < prefs->nbFiles; ++prefs->currFileIdx) {
|
||||
const char* const srcFileName = inFileNamesTable[prefs->currFileIdx];
|
||||
const char* dstFileName = NULL;
|
||||
if (outMirroredRootDirName) {
|
||||
char* validMirroredDirName = UTIL_createMirroredDestDirName(srcFileName, outMirroredRootDirName);
|
||||
@ -1724,14 +1731,11 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
} else {
|
||||
dstFileName = FIO_determineCompressedName(srcFileName, outDirName, suffix); /* cannot fail */
|
||||
}
|
||||
|
||||
if (nbFiles > 1)
|
||||
DISPLAYLEVEL(2, "\rCompressing %u/%u files. Current source: %s ", u+1, nbFiles, srcFileName);
|
||||
error |= FIO_compressFilename_srcFile(prefs, ress, dstFileName, srcFileName, compressionLevel);
|
||||
}
|
||||
|
||||
if (outDirName)
|
||||
FIO_checkFilenameCollisions(inFileNamesTable ,nbFiles);
|
||||
FIO_checkFilenameCollisions(inFileNamesTable , prefs->nbFiles);
|
||||
}
|
||||
|
||||
FIO_freeCResources(ress);
|
||||
@ -2001,8 +2005,13 @@ FIO_decompressZstdFrame(dRess_t* ress, FILE* finput,
|
||||
/* Write block */
|
||||
storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, outBuff.pos, prefs, storedSkips);
|
||||
frameSize += outBuff.pos;
|
||||
DISPLAYUPDATE(2, "\033[s%-20.20s : %u MB... \033[u",
|
||||
srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
|
||||
if (prefs->nbFiles > 1) {
|
||||
DISPLAYUPDATE(2, "\rDecompressing %u/%u files. Current source: %-20.20s : %u MB... ",
|
||||
prefs->currFileIdx+1, prefs->nbFiles, srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
|
||||
} else {
|
||||
DISPLAYUPDATE(2, "\r%-20.20s : %u MB... ",
|
||||
srcFileName, (unsigned)((alreadyDecoded+frameSize)>>20) );
|
||||
}
|
||||
|
||||
if (inBuff.pos > 0) {
|
||||
memmove(ress->srcBuffer, (char*)ress->srcBuffer + inBuff.pos, inBuff.size - inBuff.pos);
|
||||
@ -2333,8 +2342,9 @@ static int FIO_decompressFrames(dRess_t ress, FILE* srcFile,
|
||||
/* Final Status */
|
||||
DISPLAYLEVEL(2, "\r%79s\r", "");
|
||||
/* No status message in pipe mode (stdin - stdout) or multi-files mode */
|
||||
if (g_display_prefs.displayLevel > 2 || (prefs->nbFiles == 1 && !((!strcmp(srcFileName, stdinmark) && dstFileName && !strcmp(dstFileName,stdoutmark)))))
|
||||
DISPLAYLEVEL(2, "%-20s: %llu bytes \n", srcFileName, filesize);
|
||||
if (g_display_prefs.displayLevel > 2 || (g_display_prefs.displayLevel == 2 && prefs->nbFiles <= 1)) {
|
||||
DISPLAYLEVEL(2, "%-20s: %llu bytes \n", srcFileName, filesize);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2572,7 +2582,7 @@ FIO_determineDstName(const char* srcFileName, const char* outDirName)
|
||||
|
||||
int
|
||||
FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
const char** srcNamesTable, unsigned nbFiles,
|
||||
const char** srcNamesTable,
|
||||
const char* outMirroredRootDirName,
|
||||
const char* outDirName, const char* outFileName,
|
||||
const char* dictFileName)
|
||||
@ -2581,25 +2591,22 @@ FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
dRess_t ress = FIO_createDResources(prefs, dictFileName);
|
||||
|
||||
if (outFileName) {
|
||||
unsigned u;
|
||||
if (!prefs->testMode) {
|
||||
ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName);
|
||||
if (ress.dstFile == 0) EXM_THROW(19, "cannot open %s", outFileName);
|
||||
}
|
||||
for (u=0; u<nbFiles; u++) {
|
||||
DISPLAYLEVEL(2, "\rDecompressing %u/%u files. Current source: ", u+1, nbFiles);
|
||||
error |= FIO_decompressSrcFile(prefs, ress, outFileName, srcNamesTable[u]);
|
||||
for (; prefs->currFileIdx < prefs->nbFiles; prefs->currFileIdx++) {
|
||||
error |= FIO_decompressSrcFile(prefs, ress, outFileName, srcNamesTable[prefs->currFileIdx]);
|
||||
}
|
||||
if ((!prefs->testMode) && (fclose(ress.dstFile)))
|
||||
EXM_THROW(72, "Write error : %s : cannot properly close output file",
|
||||
strerror(errno));
|
||||
} else {
|
||||
unsigned int u = 0;
|
||||
if (outMirroredRootDirName)
|
||||
UTIL_mirrorSourceFilesDirectories(srcNamesTable, nbFiles, outMirroredRootDirName);
|
||||
UTIL_mirrorSourceFilesDirectories(srcNamesTable, prefs->nbFiles, outMirroredRootDirName);
|
||||
|
||||
for (u=0; u<nbFiles; u++) { /* create dstFileName */
|
||||
const char* const srcFileName = srcNamesTable[u];
|
||||
for (; prefs->currFileIdx < prefs->nbFiles; prefs->currFileIdx++) { /* create dstFileName */
|
||||
const char* const srcFileName = srcNamesTable[prefs->currFileIdx];
|
||||
const char* dstFileName = NULL;
|
||||
if (outMirroredRootDirName) {
|
||||
char* validMirroredDirName = UTIL_createMirroredDestDirName(srcFileName, outMirroredRootDirName);
|
||||
@ -2613,12 +2620,10 @@ FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
dstFileName = FIO_determineDstName(srcFileName, outDirName);
|
||||
}
|
||||
if (dstFileName == NULL) { error=1; continue; }
|
||||
if (nbFiles > 1)
|
||||
DISPLAYLEVEL(2, "\rDecompressing %u/%u files. Current source: ", u+1, nbFiles);
|
||||
error |= FIO_decompressSrcFile(prefs, ress, dstFileName, srcFileName);
|
||||
}
|
||||
if (outDirName)
|
||||
FIO_checkFilenameCollisions(srcNamesTable ,nbFiles);
|
||||
FIO_checkFilenameCollisions(srcNamesTable , prefs->nbFiles);
|
||||
}
|
||||
|
||||
FIO_freeDResources(ress);
|
||||
|
@ -97,6 +97,7 @@ void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompresse
|
||||
void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
|
||||
void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
|
||||
void FIO_setNbFiles(FIO_prefs_t* const prefs, int value);
|
||||
void FIO_setCurrFileIdx(FIO_prefs_t* const prefs, int value);
|
||||
|
||||
/*-*************************************
|
||||
* Single File functions
|
||||
@ -122,7 +123,7 @@ int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int dis
|
||||
/** FIO_compressMultipleFilenames() :
|
||||
* @return : nb of missing files */
|
||||
int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
const char** inFileNamesTable, unsigned nbFiles,
|
||||
const char** inFileNamesTable,
|
||||
const char* outMirroredDirName,
|
||||
const char* outDirName,
|
||||
const char* outFileName, const char* suffix,
|
||||
@ -132,7 +133,7 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
/** FIO_decompressMultipleFilenames() :
|
||||
* @return : nb of missing or skipped files */
|
||||
int FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
const char** srcNamesTable, unsigned nbFiles,
|
||||
const char** srcNamesTable,
|
||||
const char* outMirroredDirName,
|
||||
const char* outDirName,
|
||||
const char* outFileName,
|
||||
|
@ -1243,8 +1243,12 @@ int main(int const argCount, const char* argv[])
|
||||
DISPLAY("error : can't use --patch-from=# on multiple files \n");
|
||||
CLEAN_RETURN(1);
|
||||
}
|
||||
|
||||
/* No status message in pipe mode (stdin - stdout) */
|
||||
if (!strcmp(filenames->fileNames[0], stdinmark) && outFileName && !strcmp(outFileName,stdoutmark) && (g_displayLevel==2)) g_displayLevel=1;
|
||||
|
||||
/* IO Stream/File */
|
||||
FIO_setNbFiles(prefs, (int)filenames->tableSize);
|
||||
FIO_setNotificationLevel(g_displayLevel);
|
||||
FIO_setPatchFromMode(prefs, patchFromDictFileName != NULL);
|
||||
if (memLimit == 0) {
|
||||
@ -1302,12 +1306,10 @@ int main(int const argCount, const char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if ((filenames->tableSize==1) && outFileName) {
|
||||
if ((filenames->tableSize==1) && outFileName)
|
||||
operationResult = FIO_compressFilename(prefs, outFileName, filenames->fileNames[0], dictFileName, cLevel, compressionParams);
|
||||
} else {
|
||||
FIO_setNbFiles(prefs, (int)filenames->tableSize);
|
||||
operationResult = FIO_compressMultipleFilenames(prefs, filenames->fileNames, (unsigned)filenames->tableSize, outMirroredDirName, outDirName, outFileName, suffix, dictFileName, cLevel, compressionParams);
|
||||
}
|
||||
else
|
||||
operationResult = FIO_compressMultipleFilenames(prefs, filenames->fileNames, outMirroredDirName, outDirName, outFileName, suffix, dictFileName, cLevel, compressionParams);
|
||||
#else
|
||||
(void)contentSize; (void)suffix; (void)adapt; (void)rsyncable; (void)ultra; (void)cLevel; (void)ldmFlag; (void)literalCompressionMode; (void)targetCBlockSize; (void)streamSrcSize; (void)srcSizeHint; (void)ZSTD_strategyMap; /* not used when ZSTD_NOCOMPRESS set */
|
||||
DISPLAY("Compression not supported \n");
|
||||
@ -1318,7 +1320,7 @@ int main(int const argCount, const char* argv[])
|
||||
operationResult = FIO_decompressFilename(prefs, outFileName, filenames->fileNames[0], dictFileName);
|
||||
} else {
|
||||
FIO_setNbFiles(prefs, (int)filenames->tableSize);
|
||||
operationResult = FIO_decompressMultipleFilenames(prefs, filenames->fileNames, (unsigned)filenames->tableSize, outMirroredDirName, outDirName, outFileName, dictFileName);
|
||||
operationResult = FIO_decompressMultipleFilenames(prefs, filenames->fileNames, outMirroredDirName, outDirName, outFileName, dictFileName);
|
||||
}
|
||||
#else
|
||||
DISPLAY("Decompression not supported \n");
|
||||
|
Loading…
Reference in New Issue
Block a user