mirror of
https://github.com/lz4/lz4.git
synced 2026-10-24 01:48:57 +03:00
The manual says that -t neither creates nor removes files, and that
--rm deletes the source after a successful compression or
decompression. The CLI did not follow it for two cases :
- `lz4 -t --rm file.lz4` tested the file, then deleted it.
- With stdin as source, the output was complete, but remove("stdin")
failed and the command ended with "Remove error : stdin"
(exit code 50 when compressing, 45 when decompressing).
A file named `stdin` in the working directory would have been deleted.
One helper, LZ4IO_mustRemoveSrcFile(), now decides. It answers no in
test mode and for stdin, and both remove sites use it :
LZ4IO_finishCompressedFile() and LZ4IO_decompressSrcFile().
A regular source file is still removed.
131 lines
6.5 KiB
Bash
Executable File
131 lines
6.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
FPREFIX="tmp-tlb"
|
|
|
|
set -e
|
|
|
|
remove () {
|
|
rm -rf $FPREFIX*
|
|
}
|
|
|
|
trap remove EXIT
|
|
|
|
set -x
|
|
|
|
datagen -g0 | lz4 -v | lz4 -t
|
|
datagen -g16KB | lz4 -9 | lz4 -t
|
|
datagen -g20KB > $FPREFIX-dg20k
|
|
lz4 < $FPREFIX-dg20k | lz4 -d > $FPREFIX-dec
|
|
diff -q $FPREFIX-dg20k $FPREFIX-dec
|
|
lz4 --no-frame-crc < $FPREFIX-dg20k | lz4 -d > $FPREFIX-dec
|
|
diff -q $FPREFIX-dg20k $FPREFIX-dec
|
|
datagen | lz4 -BI | lz4 -t
|
|
datagen | lz4 --no-crc | lz4 -t
|
|
datagen -g6M -P99 | lz4 -9BD | lz4 -t
|
|
datagen -g17M | lz4 -9v | lz4 -qt
|
|
datagen -g33M | lz4 --no-frame-crc | lz4 -t
|
|
datagen -g256MB | lz4 -vqB4D | lz4 -t --no-crc
|
|
echo "hello world" > $FPREFIX-hw
|
|
lz4 --rm -f $FPREFIX-hw $FPREFIX-hw.lz4
|
|
test ! -f $FPREFIX-hw # must fail (--rm)
|
|
test -f $FPREFIX-hw.lz4
|
|
lz4 -d --rm -f $FPREFIX-hw.lz4
|
|
test ! -f $FPREFIX-hw.lz4
|
|
lz4 -l --rm -f $FPREFIX-hw $FPREFIX-hw.lz4 # legacy format
|
|
test ! -f $FPREFIX-hw # must fail (--rm)
|
|
lz4 -d --rm -f $FPREFIX-hw.lz4
|
|
test ! -f $FPREFIX-hw.lz4
|
|
touch -t 202001010000 $FPREFIX-hw
|
|
lz4 -f $FPREFIX-hw $FPREFIX-hw.lz4
|
|
test ! $FPREFIX-hw.lz4 -nt $FPREFIX-hw # keeps modification time
|
|
lz4 -l -f $FPREFIX-hw $FPREFIX-hw.lz4
|
|
test ! $FPREFIX-hw.lz4 -nt $FPREFIX-hw # same with legacy format
|
|
rm $FPREFIX-hw.lz4
|
|
lz4 --rm -f $FPREFIX-hw > /dev/null
|
|
test -f $FPREFIX-hw.lz4 # no more implicit stdout
|
|
lz4cat $FPREFIX-hw.lz4 | grep "hello world"
|
|
unlz4 --rm $FPREFIX-hw.lz4 $FPREFIX-hw
|
|
test -f $FPREFIX-hw
|
|
test ! -f $FPREFIX-hw.lz4 # must fail (--rm)
|
|
test ! -f $FPREFIX-hw.lz4.lz4 # must fail (unlz4)
|
|
lz4cat $FPREFIX-hw # pass-through mode
|
|
test -f $FPREFIX-hw
|
|
test ! -f $FPREFIX-hw.lz4 # must fail (lz4cat)
|
|
lz4 $FPREFIX-hw $FPREFIX-hw.lz4 # creates $FPREFIX-hw.lz4
|
|
lz4cat < $FPREFIX-hw.lz4 > ${FPREFIX}3 # checks lz4cat works with stdin (#285)
|
|
diff -q $FPREFIX-hw ${FPREFIX}3
|
|
lz4cat < $FPREFIX-hw > ${FPREFIX}2 # checks lz4cat works in pass-through mode
|
|
diff -q $FPREFIX-hw ${FPREFIX}2
|
|
cp $FPREFIX-hw ./-d
|
|
lz4 --rm -- -d -d.lz4 # compresses ./d into ./-d.lz4
|
|
test -f ./-d.lz4
|
|
test ! -f ./-d
|
|
mv ./-d.lz4 ./-z
|
|
lz4 -d --rm -- -z ${FPREFIX}4 # uncompresses ./-z into $FPREFIX4
|
|
test ! -f ./-z
|
|
diff -q $FPREFIX-hw ${FPREFIX}4
|
|
lz4 ${FPREFIX}2 ${FPREFIX}3 ${FPREFIX}4 && exit 1 # must fail: refuse to handle 3+ file names
|
|
mkdir -p ${FPREFIX}-dir
|
|
lz4 ${FPREFIX}-dir && exit 1 # must fail: refuse to compress directory
|
|
test ! -f ${FPREFIX}-dir.lz4 # must not create artifact (#1211)
|
|
lz4 -f $FPREFIX-hw # create $FPREFIX-hw.lz4, for next tests
|
|
lz4 --list $FPREFIX-hw.lz4 # test --list on valid single-frame file
|
|
lz4 --list < $FPREFIX-hw.lz4 # test --list from stdin (file only)
|
|
lz4 --list goldenSamples/dictID.bin # test --list on a frame carrying a dictID (11-byte header)
|
|
head -c $(( $(wc -c < $FPREFIX-hw.lz4) - 4 )) $FPREFIX-hw.lz4 > $FPREFIX-trunc.lz4
|
|
lz4 --list $FPREFIX-trunc.lz4 && exit 1 # must fail: truncated frame (content checksum missing)
|
|
cat $FPREFIX-hw >> $FPREFIX-hw.lz4
|
|
lz4 -f $FPREFIX-hw.lz4 && exit 1 # uncompress valid frame followed by invalid data (must fail now)
|
|
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
|
|
test "$(datagen -g20KB | lz4 -c --fast | wc -c)" -lt "$(datagen -g20KB | lz4 -c --fast=9 | wc -c)" # -1 vs -9
|
|
test "$(datagen -g20KB | lz4 -c -1 | wc -c)" -lt "$(datagen -g20KB| lz4 -c --fast=1 | wc -c)" # 1 vs -1
|
|
test "$(datagen -g20KB | lz4 -c --fast=1 | wc -c)" -eq "$(datagen -g20KB| lz4 -c --fast| wc -c)" # checks default fast compression is -1
|
|
test "$(lz4 -c -l -1 $FPREFIX-dg20k | wc -c)" -lt "$(lz4 -c -l --fast=1 $FPREFIX-dg20k | wc -c)" # same with legacy format
|
|
lz4 -c -l --fast=2147483647 $FPREFIX-dg20k > /dev/null # legacy format : acceleration capped without overflow
|
|
lz4 -c --fast=0 $FPREFIX-dg20k && exit 1 # lz4 should fail when fast=0
|
|
lz4 -c --fast=-1 $FPREFIX-dg20k && exit 1 # lz4 should fail when fast=-1
|
|
lz4 -c --fast=5x $FPREFIX-dg20k && exit 1 # lz4 should fail on trailing garbage
|
|
lz4 -c --threadsX 2 $FPREFIX-dg20k && exit 1 # lz4 should fail on unknown long command
|
|
# numeric arguments must not silently overflow
|
|
lz4 -c --fast=3000000000 $FPREFIX-dg20k > /dev/null && exit 1 # > INT_MAX
|
|
lz4 -c --fast=4294967297 $FPREFIX-dg20k > /dev/null && exit 1 # > UINT_MAX (would wrap to 1)
|
|
lz4 -c -3000000000 $FPREFIX-dg20k > /dev/null && exit 1 # > INT_MAX
|
|
lz4 -c -4294967305 $FPREFIX-dg20k > /dev/null && exit 1 # > UINT_MAX (would wrap to 9)
|
|
lz4 -c -T4294967297 $FPREFIX-dg20k > /dev/null && exit 1 # > UINT_MAX (would wrap to 1)
|
|
# an overflowing LZ4_CLEVEL is ignored, like other invalid values
|
|
test "$(LZ4_CLEVEL=4294967305 lz4 -c $FPREFIX-dg20k | wc -c)" -eq "$(lz4 -c $FPREFIX-dg20k | wc -c)"
|
|
# acceleration (--fast=# + 1) is capped at LZ4_ACCELERATION_MAX (65537) :
|
|
# the largest --fast value behaves like --fast=65536, without overflow
|
|
lz4 -c --fast=65536 $FPREFIX-dg20k > $FPREFIX-fastmax.lz4
|
|
lz4 -c --fast=2147483647 $FPREFIX-dg20k | cmp - $FPREFIX-fastmax.lz4
|
|
lz4 -bq --fast=2147483647 -i0 $FPREFIX-dg20k
|
|
# Multithreading commands
|
|
datagen -g16M | lz4 -T2 | lz4 -t
|
|
datagen -g16M | lz4 --threads=2 | lz4 -t
|
|
# High --fast values can result in out-of-bound dereferences #876
|
|
datagen -g1M | lz4 -c --fast=999999999 > $FPREFIX-trash
|
|
# Test for #596
|
|
echo "TEST" > $FPREFIX-test
|
|
lz4 -m $FPREFIX-test
|
|
lz4 $FPREFIX-test.lz4 $FPREFIX-test2
|
|
diff -q $FPREFIX-test $FPREFIX-test2
|
|
# bug #1374
|
|
datagen -g4194302 | lz4 -B4 -c > $FPREFIX-test3
|