FIO_compressMultipleFilenames() : * compress nbFiles files * into either one destination (outFileName), * or into one file each (outFileName == NULL, but suffix != NULL), * or into a destination folder (specified with -O) */
| 1784 | * or into a destination folder (specified with -O) |
| 1785 | */ |
| 1786 | int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx, |
| 1787 | FIO_prefs_t* const prefs, |
| 1788 | const char** inFileNamesTable, |
| 1789 | const char* outMirroredRootDirName, |
| 1790 | const char* outDirName, |
| 1791 | const char* outFileName, const char* suffix, |
| 1792 | const char* dictFileName, int compressionLevel, |
| 1793 | ZSTD_compressionParameters comprParams) |
| 1794 | { |
| 1795 | int status; |
| 1796 | int error = 0; |
| 1797 | cRess_t ress = FIO_createCResources(prefs, dictFileName, |
| 1798 | FIO_getLargestFileSize(inFileNamesTable, fCtx->nbFilesTotal), |
| 1799 | compressionLevel, comprParams); |
| 1800 | |
| 1801 | /* init */ |
| 1802 | assert(outFileName != NULL || suffix != NULL); |
| 1803 | if (outFileName != NULL) { /* output into a single destination (stdout typically) */ |
| 1804 | if (FIO_removeMultiFilesWarning(fCtx, prefs, outFileName, 1 /* displayLevelCutoff */)) { |
| 1805 | FIO_freeCResources(&ress); |
| 1806 | return 1; |
| 1807 | } |
| 1808 | ress.dstFile = FIO_openDstFile(fCtx, prefs, NULL, outFileName); |
| 1809 | if (ress.dstFile == NULL) { /* could not open outFileName */ |
| 1810 | error = 1; |
| 1811 | } else { |
| 1812 | for (; fCtx->currFileIdx < fCtx->nbFilesTotal; ++fCtx->currFileIdx) { |
| 1813 | status = FIO_compressFilename_srcFile(fCtx, prefs, ress, outFileName, inFileNamesTable[fCtx->currFileIdx], compressionLevel); |
| 1814 | if (!status) fCtx->nbFilesProcessed++; |
| 1815 | error |= status; |
| 1816 | } |
| 1817 | if (fclose(ress.dstFile)) |
| 1818 | EXM_THROW(29, "Write error (%s) : cannot properly close %s", |
| 1819 | strerror(errno), outFileName); |
| 1820 | ress.dstFile = NULL; |
| 1821 | } |
| 1822 | } else { |
| 1823 | if (outMirroredRootDirName) |
| 1824 | UTIL_mirrorSourceFilesDirectories(inFileNamesTable, fCtx->nbFilesTotal, outMirroredRootDirName); |
| 1825 | |
| 1826 | for (; fCtx->currFileIdx < fCtx->nbFilesTotal; ++fCtx->currFileIdx) { |
| 1827 | const char* const srcFileName = inFileNamesTable[fCtx->currFileIdx]; |
| 1828 | const char* dstFileName = NULL; |
| 1829 | if (outMirroredRootDirName) { |
| 1830 | char* validMirroredDirName = UTIL_createMirroredDestDirName(srcFileName, outMirroredRootDirName); |
| 1831 | if (validMirroredDirName) { |
| 1832 | dstFileName = FIO_determineCompressedName(srcFileName, validMirroredDirName, suffix); |
| 1833 | free(validMirroredDirName); |
| 1834 | } else { |
| 1835 | DISPLAYLEVEL(2, "zstd: --output-dir-mirror cannot compress '%s' into '%s' \n", srcFileName, outMirroredRootDirName); |
| 1836 | error=1; |
| 1837 | continue; |
| 1838 | } |
| 1839 | } else { |
| 1840 | dstFileName = FIO_determineCompressedName(srcFileName, outDirName, suffix); /* cannot fail */ |
| 1841 | } |
| 1842 | status = FIO_compressFilename_srcFile(fCtx, prefs, ress, dstFileName, srcFileName, compressionLevel); |
| 1843 | if (!status) fCtx->nbFilesProcessed++; |
no test coverage detected