mirror of
https://github.com/lz4/lz4
synced 2026-01-18 17:21:30 +01:00
make file open errors recoverable in legacy mode
This commit is contained in:
@@ -836,9 +836,9 @@ int main(int argCount, const char** argv)
|
||||
DISPLAYLEVEL(3, "! Generating LZ4 Legacy format (deprecated) ! \n");
|
||||
if(multiple_inputs){
|
||||
const char* const leg_extension = !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION;
|
||||
LZ4IO_compressMultipleFilenames_Legacy(inFileNames, (int)ifnIdx, leg_extension, cLevel, prefs);
|
||||
operationResult = LZ4IO_compressMultipleFilenames_Legacy(inFileNames, (int)ifnIdx, leg_extension, cLevel, prefs);
|
||||
} else {
|
||||
LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel, prefs);
|
||||
operationResult = LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel, prefs);
|
||||
}
|
||||
} else {
|
||||
if (multiple_inputs) {
|
||||
|
||||
@@ -809,24 +809,27 @@ int LZ4IO_compressFilename_Legacy(const char* input_filename,
|
||||
/* Init & checks */
|
||||
TIME_t const timeStart = TIME_getTime();
|
||||
clock_t const cpuStart = clock();
|
||||
if (finput == NULL)
|
||||
END_PROCESS(20, "%s : open file error ", input_filename);
|
||||
if (tPool == NULL || wPool == NULL)
|
||||
END_PROCESS(20, "threadpool creation error ");
|
||||
if (wr.buffers == NULL)
|
||||
END_PROCESS(20, "can't allocate write register");
|
||||
|
||||
if (finput == NULL) {
|
||||
/* read file error : recoverable */
|
||||
return 1;
|
||||
}
|
||||
foutput = LZ4IO_openDstFile(output_filename, prefs);
|
||||
if (foutput == NULL) {
|
||||
fclose(finput);
|
||||
END_PROCESS(20, "%s : open file error ", input_filename);
|
||||
/* write file error : recoverable */
|
||||
return 1;
|
||||
}
|
||||
if (tPool == NULL || wPool == NULL)
|
||||
END_PROCESS(21, "threadpool creation error ");
|
||||
if (wr.buffers == NULL)
|
||||
END_PROCESS(22, "can't allocate write register");
|
||||
|
||||
|
||||
/* Write Archive Header */
|
||||
{ char outHeader[MAGICNUMBER_SIZE];
|
||||
LZ4IO_writeLE32(outHeader, LEGACY_MAGICNUMBER);
|
||||
if (fwrite(outHeader, 1, MAGICNUMBER_SIZE, foutput) != MAGICNUMBER_SIZE)
|
||||
END_PROCESS(22, "Write error : cannot write header");
|
||||
END_PROCESS(23, "Write error : cannot write header");
|
||||
}
|
||||
wr.totalCSize = MAGICNUMBER_SIZE;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ cmp ${FPREFIX}2 ${FPREFIX}2-orig
|
||||
cmp ${FPREFIX}3 ${FPREFIX}3-orig
|
||||
# compress multiple files into stdout using legacy format
|
||||
cat ${FPREFIX}1.lz4 ${FPREFIX}2.lz4 ${FPREFIX}3.lz4 > $FPREFIX-concat1
|
||||
rm $FPREFIX*.lz4
|
||||
rm -f $FPREFIX*.lz4
|
||||
lz4 -l -m ${FPREFIX}1 ${FPREFIX}2 ${FPREFIX}3 -c > $FPREFIX-concat2
|
||||
test ! -f ${FPREFIX}1.lz4 # must not create .lz4 artefact
|
||||
cmp $FPREFIX-concat1 $FPREFIX-concat2 # must be equivalent
|
||||
@@ -45,5 +45,7 @@ lz4 -d -l -m ${FPREFIX}1.lz4 ${FPREFIX}2.lz4 ${FPREFIX}3.lz4 -c > $FPREFIX-conca
|
||||
test ! -f ${FPREFIX}1 # must not create file artefact
|
||||
cmp $FPREFIX-concat1 $FPREFIX-concat2 # must be equivalent
|
||||
# # # compress multiple files, one of which is absent (must fail)
|
||||
rm -f $FPREFIX-concat2.lz4
|
||||
lz4 -f -l -m $FPREFIX-concat1 notHere-legacy $FPREFIX-concat2 && exit 1 # must fail : notHere-legacy not present
|
||||
test -f $FPREFIX-concat2.lz4 # notHere was a non-blocking error, concat2.lz4 should be present
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user