mirror of
https://github.com/lz4/lz4.git
synced 2026-10-24 01:48:57 +03:00
Merge pull request #1931 from lz4/cli_rm_test_stdin
cli: --rm skips -t and stdin
This commit is contained in:
1
NEWS
1
NEWS
@@ -56,6 +56,7 @@ cli : output buffer no longer grows with the nb of threads : more threads withi
|
||||
cli : a source file modified, renamed or replaced during its compression is detected, and kept with `--rm` ; error 54 when the output can't be verified
|
||||
cli : `lz4 -l` could hang on Windows with an empty input, as could decoding the resulting legacy stream
|
||||
cli : `--rm` keeps the source file after a decompression failure, by @Furan666
|
||||
cli : `lz4 -t --rm` no longer removes the tested file, and `--rm` with `stdin` no longer fails nor removes a file named `stdin`, by @Nexory
|
||||
cli : `lz4 -t -m` no longer writes decoded content to stdout, reported by @tansy
|
||||
cli : `lz4 --list` rejects truncated frames, instead of reporting them as valid, by @jmestwa-coder
|
||||
cli : numeric arguments that overflow are rejected, instead of silently wrapping around, by @akashdeshmukh-git
|
||||
|
||||
@@ -423,6 +423,17 @@ static int LZ4IO_isStdout(const char* s)
|
||||
return UTIL_sameString(s, stdoutmark);
|
||||
}
|
||||
|
||||
/* LZ4IO_mustRemoveSrcFile() :
|
||||
* `--rm` only applies to a regular source file :
|
||||
* not in test mode, which removes nothing (see lz4.1.md),
|
||||
* and not when reading from stdin, which is not a file. */
|
||||
static int LZ4IO_mustRemoveSrcFile(const LZ4IO_prefs_t* prefs, const char* srcFileName)
|
||||
{
|
||||
return prefs->removeSrcFile
|
||||
&& !prefs->testMode
|
||||
&& !LZ4IO_isStdin(srcFileName);
|
||||
}
|
||||
|
||||
|
||||
/* ************************************************************************ **
|
||||
** ********************** LZ4 File / Pipe compression ********************* **
|
||||
@@ -881,7 +892,7 @@ LZ4IO_finishCompressedFile(FILE* srcFile, FILE* dstFile,
|
||||
UTIL_setFileStat(dstFileName, &statbuf);
|
||||
} }
|
||||
|
||||
if (io_prefs->removeSrcFile && !srcModified && !srcReplaced) { /* remove source file : --rm */
|
||||
if (LZ4IO_mustRemoveSrcFile(io_prefs, srcFileName) && !srcModified && !srcReplaced) { /* remove source file : --rm */
|
||||
if (remove(srcFileName))
|
||||
END_PROCESS(50, "Remove error : %s: %s", srcFileName, strerror(errno));
|
||||
}
|
||||
@@ -2637,7 +2648,7 @@ LZ4IO_decompressSrcFile(unsigned long long* outGenSize,
|
||||
|
||||
/* Close input */
|
||||
fclose(finput);
|
||||
if (!result && prefs->removeSrcFile) { /* --rm */
|
||||
if (!result && LZ4IO_mustRemoveSrcFile(prefs, input_filename)) { /* --rm */
|
||||
if (remove(input_filename))
|
||||
END_PROCESS(45, "Remove error : %s: %s", input_filename, strerror(errno));
|
||||
}
|
||||
|
||||
@@ -80,6 +80,17 @@ printf '\120\052\115\030\000\000\000\000BAD!' > $FPREFIX-bad.lz4
|
||||
cp $FPREFIX-bad.lz4 $FPREFIX-bad-before.lz4
|
||||
lz4 -d --rm -f $FPREFIX-bad.lz4 $FPREFIX-bad.out && exit 1
|
||||
diff -q $FPREFIX-bad-before.lz4 $FPREFIX-bad.lz4 # --rm keeps source after decoding failure
|
||||
echo "rm test" > $FPREFIX-rm
|
||||
lz4 $FPREFIX-rm $FPREFIX-rm.lz4
|
||||
cp $FPREFIX-rm.lz4 $FPREFIX-rm-before.lz4
|
||||
lz4 -t --rm $FPREFIX-rm.lz4
|
||||
diff -q $FPREFIX-rm-before.lz4 $FPREFIX-rm.lz4 # -t --rm keeps its input ("No files are created nor removed")
|
||||
lz4 -t --rm < $FPREFIX-rm.lz4 # nothing to remove when reading stdin
|
||||
lz4 -c --rm < $FPREFIX-rm | lz4 -t # idem when compressing
|
||||
lz4 -dc --rm < $FPREFIX-rm.lz4 | diff -q - $FPREFIX-rm # idem when decompressing
|
||||
lz4 -d --rm $FPREFIX-rm.lz4 $FPREFIX-rm-out
|
||||
test ! -f $FPREFIX-rm.lz4 # --rm still removes a regular source file
|
||||
test -f $FPREFIX-rm-out
|
||||
lz4 -BX $FPREFIX-hw -c -q | lz4 -tv # test block checksum
|
||||
# datagen -g20KB generates the same file every single time
|
||||
# cannot save output of datagen -g20KB as input file to lz4 because the following shell commands are run before datagen -g20KB
|
||||
|
||||
Reference in New Issue
Block a user