[zstdcli] Refuse to overwrite input file

Compare the input and output files by their inode number and
refuse to open the output file if the input file is the same.

This doesn't work when (de)compressing multiple files to a single
file, but that is a very uncommon use case, mostly used for
benchmarking by me.

Fixes #1422.
This commit is contained in:
Nick Terrell
2018-12-18 15:29:54 -08:00
parent 517d8c984c
commit cd2c8defad
2 changed files with 18 additions and 5 deletions
+3
View File
@@ -183,6 +183,9 @@ $ECHO "test: --no-progress flag"
$ZSTD tmpro -c --no-progress | $ZSTD -d -o "$INTOVOID" --no-progress
$ZSTD tmpro -cv --no-progress | $ZSTD -dv -o "$INTOVOID" --no-progress
rm -f tmpro tmpro.zst
$ECHO "test: overwrite input file (must fail)"
$ZSTD tmp -fo tmp && die "zstd overwrote the input file"
$ZSTD tmp.zst -dfo tmp.zst && die "zstd overwrote the input file"
$ECHO "test : file removal"