MCPcopy Create free account
hub / github.com/F-Stack/f-stack / FIO_decompressDstFile

Function FIO_decompressDstFile

freebsd/contrib/zstd/programs/fileio.c:2491–2540  ·  view source on GitHub ↗

FIO_decompressDstFile() : open `dstFileName`, or path-through if ress.dstFile is already != 0, then start decompression process (FIO_decompressFrames()). @return : 0 : OK 1 : operation aborted */

Source from the content-addressed store, hash-verified

2489 1 : operation aborted
2490*/
2491static int FIO_decompressDstFile(FIO_ctx_t* const fCtx,
2492 FIO_prefs_t* const prefs,
2493 dRess_t ress, FILE* srcFile,
2494 const char* dstFileName, const char* srcFileName)
2495{
2496 int result;
2497 stat_t statbuf;
2498 int transfer_permissions = 0;
2499 int releaseDstFile = 0;
2500
2501 if ((ress.dstFile == NULL) && (prefs->testMode==0)) {
2502 releaseDstFile = 1;
2503
2504 ress.dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName);
2505 if (ress.dstFile==NULL) return 1;
2506
2507 /* Must only be added after FIO_openDstFile() succeeds.
2508 * Otherwise we may delete the destination file if it already exists,
2509 * and the user presses Ctrl-C when asked if they wish to overwrite.
2510 */
2511 addHandler(dstFileName);
2512
2513 if ( strcmp(srcFileName, stdinmark) /* special case : don't transfer permissions from stdin */
2514 && UTIL_stat(srcFileName, &statbuf)
2515 && UTIL_isRegularFileStat(&statbuf) )
2516 transfer_permissions = 1;
2517 }
2518
2519 result = FIO_decompressFrames(fCtx, ress, srcFile, prefs, dstFileName, srcFileName);
2520
2521 if (releaseDstFile) {
2522 FILE* const dstFile = ress.dstFile;
2523 clearHandler();
2524 ress.dstFile = NULL;
2525 if (fclose(dstFile)) {
2526 DISPLAYLEVEL(1, "zstd: %s: %s \n", dstFileName, strerror(errno));
2527 result = 1;
2528 }
2529
2530 if ( (result != 0) /* operation failure */
2531 && strcmp(dstFileName, stdoutmark) /* special case : don't remove() stdout */
2532 ) {
2533 FIO_removeFile(dstFileName); /* remove decompression artefact; note: don't do anything special if remove() fails */
2534 } else if ( transfer_permissions /* file permissions correctly extracted from src */ ) {
2535 UTIL_setFileStat(dstFileName, &statbuf); /* transfer file permissions from src into dst */
2536 }
2537 }
2538
2539 return result;
2540}
2541
2542
2543/** FIO_decompressSrcFile() :

Callers 1

FIO_decompressSrcFileFunction · 0.85

Calls 9

FIO_openDstFileFunction · 0.85
addHandlerFunction · 0.85
strcmpFunction · 0.85
UTIL_statFunction · 0.85
UTIL_isRegularFileStatFunction · 0.85
FIO_decompressFramesFunction · 0.85
clearHandlerFunction · 0.85
FIO_removeFileFunction · 0.85
UTIL_setFileStatFunction · 0.85

Tested by

no test coverage detected