mirror of
https://github.com/facebook/zstd.git
synced 2025-10-15 00:02:02 -04:00
Merge pull request #2525 from felixhandte/fix-file-permissions-again
Improve Setting Permissions of Created Files
This commit is contained in:
commit
b062d97520
@ -25,9 +25,10 @@
|
||||
***************************************/
|
||||
#include "platform.h" /* Large Files support, SET_BINARY_MODE */
|
||||
#include "util.h" /* UTIL_getFileSize, UTIL_isRegularFile, UTIL_isSameFile */
|
||||
#include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */
|
||||
#include <stdio.h> /* fprintf, open, fdopen, fread, _fileno, stdin, stdout */
|
||||
#include <stdlib.h> /* malloc, free */
|
||||
#include <string.h> /* strcmp, strlen */
|
||||
#include <fcntl.h> /* O_WRONLY */
|
||||
#include <assert.h>
|
||||
#include <errno.h> /* errno */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
@ -73,6 +74,14 @@
|
||||
|
||||
#define FNSPACE 30
|
||||
|
||||
/* Default file permissions 0666 (modulated by umask) */
|
||||
#if !defined(_WIN32)
|
||||
/* These macros aren't defined on windows. */
|
||||
#define DEFAULT_FILE_PERMISSIONS (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
|
||||
#else
|
||||
#define DEFAULT_FILE_PERMISSIONS (0666)
|
||||
#endif
|
||||
|
||||
/*-*************************************
|
||||
* Macros
|
||||
***************************************/
|
||||
@ -637,7 +646,8 @@ static FILE* FIO_openSrcFile(const FIO_prefs_t* const prefs, const char* srcFile
|
||||
* @result : FILE* to `dstFileName`, or NULL if it fails */
|
||||
static FILE*
|
||||
FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
||||
const char* srcFileName, const char* dstFileName)
|
||||
const char* srcFileName, const char* dstFileName,
|
||||
const int mode)
|
||||
{
|
||||
if (prefs->testMode) return NULL; /* do not open file in test mode */
|
||||
|
||||
@ -664,7 +674,6 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
||||
|
||||
if (UTIL_isRegularFile(dstFileName)) {
|
||||
/* Check if destination file already exists */
|
||||
FILE* const fCheck = fopen( dstFileName, "rb" );
|
||||
#if !defined(_WIN32)
|
||||
/* this test does not work on Windows :
|
||||
* `NUL` and `nul` are detected as regular files */
|
||||
@ -673,26 +682,39 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
|
||||
dstFileName);
|
||||
}
|
||||
#endif
|
||||
if (fCheck != NULL) { /* dst file exists, authorization prompt */
|
||||
fclose(fCheck);
|
||||
if (!prefs->overwrite) {
|
||||
if (g_display_prefs.displayLevel <= 1) {
|
||||
/* No interaction possible */
|
||||
DISPLAY("zstd: %s already exists; not overwritten \n",
|
||||
dstFileName);
|
||||
return NULL;
|
||||
}
|
||||
DISPLAY("zstd: %s already exists; ", dstFileName);
|
||||
if (UTIL_requireUserConfirmation("overwrite (y/n) ? ", "Not overwritten \n", "yY", fCtx->hasStdinInput))
|
||||
return NULL;
|
||||
if (!prefs->overwrite) {
|
||||
if (g_display_prefs.displayLevel <= 1) {
|
||||
/* No interaction possible */
|
||||
DISPLAY("zstd: %s already exists; not overwritten \n",
|
||||
dstFileName);
|
||||
return NULL;
|
||||
}
|
||||
/* need to unlink */
|
||||
FIO_removeFile(dstFileName);
|
||||
} }
|
||||
DISPLAY("zstd: %s already exists; ", dstFileName);
|
||||
if (UTIL_requireUserConfirmation("overwrite (y/n) ? ", "Not overwritten \n", "yY", fCtx->hasStdinInput))
|
||||
return NULL;
|
||||
}
|
||||
/* need to unlink */
|
||||
FIO_removeFile(dstFileName);
|
||||
}
|
||||
|
||||
{ const int old_umask = UTIL_umask(0177); /* u-x,go-rwx */
|
||||
FILE* const f = fopen( dstFileName, "wb" );
|
||||
UTIL_umask(old_umask);
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
/* Windows requires opening the file as a "binary" file to avoid
|
||||
* mangling. This macro doesn't exist on unix. */
|
||||
const int openflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY;
|
||||
const int fd = _open(dstFileName, openflags, mode);
|
||||
FILE* f = NULL;
|
||||
if (fd != -1) {
|
||||
f = _fdopen(fd, "wb");
|
||||
}
|
||||
#else
|
||||
const int openflags = O_WRONLY|O_CREAT|O_TRUNC;
|
||||
const int fd = open(dstFileName, openflags, mode);
|
||||
FILE* f = NULL;
|
||||
if (fd != -1) {
|
||||
f = fdopen(fd, "wb");
|
||||
}
|
||||
#endif
|
||||
if (f == NULL) {
|
||||
DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno));
|
||||
}
|
||||
@ -1615,23 +1637,24 @@ static int FIO_compressFilename_dstFile(FIO_ctx_t* const fCtx,
|
||||
int closeDstFile = 0;
|
||||
int result;
|
||||
stat_t statbuf;
|
||||
int transfer_permissions = 0;
|
||||
assert(ress.srcFile != NULL);
|
||||
if (ress.dstFile == NULL) {
|
||||
int dstFilePermissions = DEFAULT_FILE_PERMISSIONS;
|
||||
if ( strcmp (srcFileName, stdinmark)
|
||||
&& UTIL_stat(srcFileName, &statbuf)
|
||||
&& UTIL_isRegularFileStat(&statbuf) ) {
|
||||
dstFilePermissions = statbuf.st_mode;
|
||||
}
|
||||
|
||||
closeDstFile = 1;
|
||||
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: opening dst: %s \n", dstFileName);
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName);
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName, dstFilePermissions);
|
||||
if (ress.dstFile==NULL) return 1; /* could not open dstFileName */
|
||||
/* Must only be added after FIO_openDstFile() succeeds.
|
||||
* Otherwise we may delete the destination file if it already exists,
|
||||
* and the user presses Ctrl-C when asked if they wish to overwrite.
|
||||
*/
|
||||
addHandler(dstFileName);
|
||||
|
||||
if ( strcmp (srcFileName, stdinmark)
|
||||
&& UTIL_stat(srcFileName, &statbuf)
|
||||
&& UTIL_isRegularFileStat(&statbuf) )
|
||||
transfer_permissions = 1;
|
||||
}
|
||||
|
||||
result = FIO_compressFilename_internal(fCtx, prefs, ress, dstFileName, srcFileName, compressionLevel);
|
||||
@ -1651,11 +1674,6 @@ static int FIO_compressFilename_dstFile(FIO_ctx_t* const fCtx,
|
||||
&& strcmp(dstFileName, stdoutmark) /* special case : don't remove() stdout */
|
||||
) {
|
||||
FIO_removeFile(dstFileName); /* remove compression artefact; note don't do anything special if remove() fails */
|
||||
} else if (transfer_permissions) {
|
||||
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: transferring permissions into dst: %s \n", dstFileName);
|
||||
UTIL_setFileStat(dstFileName, &statbuf);
|
||||
} else {
|
||||
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: do not transfer permissions into dst: %s \n", dstFileName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1827,7 +1845,7 @@ int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
|
||||
FIO_freeCResources(&ress);
|
||||
return 1;
|
||||
}
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, NULL, outFileName);
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, NULL, outFileName, DEFAULT_FILE_PERMISSIONS);
|
||||
if (ress.dstFile == NULL) { /* could not open outFileName */
|
||||
error = 1;
|
||||
} else {
|
||||
@ -2517,13 +2535,19 @@ static int FIO_decompressDstFile(FIO_ctx_t* const fCtx,
|
||||
{
|
||||
int result;
|
||||
stat_t statbuf;
|
||||
int transfer_permissions = 0;
|
||||
int releaseDstFile = 0;
|
||||
|
||||
if ((ress.dstFile == NULL) && (prefs->testMode==0)) {
|
||||
int dstFilePermissions = DEFAULT_FILE_PERMISSIONS;
|
||||
if ( strcmp(srcFileName, stdinmark) /* special case : don't transfer permissions from stdin */
|
||||
&& UTIL_stat(srcFileName, &statbuf)
|
||||
&& UTIL_isRegularFileStat(&statbuf) ) {
|
||||
dstFilePermissions = statbuf.st_mode;
|
||||
}
|
||||
|
||||
releaseDstFile = 1;
|
||||
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName);
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName, dstFilePermissions);
|
||||
if (ress.dstFile==NULL) return 1;
|
||||
|
||||
/* Must only be added after FIO_openDstFile() succeeds.
|
||||
@ -2531,11 +2555,6 @@ static int FIO_decompressDstFile(FIO_ctx_t* const fCtx,
|
||||
* and the user presses Ctrl-C when asked if they wish to overwrite.
|
||||
*/
|
||||
addHandler(dstFileName);
|
||||
|
||||
if ( strcmp(srcFileName, stdinmark) /* special case : don't transfer permissions from stdin */
|
||||
&& UTIL_stat(srcFileName, &statbuf)
|
||||
&& UTIL_isRegularFileStat(&statbuf) )
|
||||
transfer_permissions = 1;
|
||||
}
|
||||
|
||||
result = FIO_decompressFrames(fCtx, ress, srcFile, prefs, dstFileName, srcFileName);
|
||||
@ -2553,8 +2572,6 @@ static int FIO_decompressDstFile(FIO_ctx_t* const fCtx,
|
||||
&& strcmp(dstFileName, stdoutmark) /* special case : don't remove() stdout */
|
||||
) {
|
||||
FIO_removeFile(dstFileName); /* remove decompression artefact; note: don't do anything special if remove() fails */
|
||||
} else if ( transfer_permissions /* file permissions correctly extracted from src */ ) {
|
||||
UTIL_setFileStat(dstFileName, &statbuf); /* transfer file permissions from src into dst */
|
||||
}
|
||||
}
|
||||
|
||||
@ -2756,7 +2773,7 @@ FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
|
||||
return 1;
|
||||
}
|
||||
if (!prefs->testMode) {
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, NULL, outFileName);
|
||||
ress.dstFile = FIO_openDstFile(fCtx, prefs, NULL, outFileName, DEFAULT_FILE_PERMISSIONS);
|
||||
if (ress.dstFile == 0) EXM_THROW(19, "cannot open %s", outFileName);
|
||||
}
|
||||
for (; fCtx->currFileIdx < fCtx->nbFilesTotal; fCtx->currFileIdx++) {
|
||||
|
@ -22,6 +22,7 @@ extern "C" {
|
||||
****************************************/
|
||||
#if defined(_MSC_VER)
|
||||
# define _CRT_SECURE_NO_WARNINGS /* Disable Visual Studio warning messages for fopen, strncpy, strerror */
|
||||
# define _CRT_NONSTDC_NO_WARNINGS /* Disable C4996 complaining about posix function names */
|
||||
# if (_MSC_VER <= 1800) /* 1800 == Visual Studio 2013 */
|
||||
# define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before <io.h> and <windows.h> */
|
||||
# define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */
|
||||
|
@ -159,15 +159,6 @@ int UTIL_chmod(char const* filename, const stat_t* statbuf, mode_t permissions)
|
||||
return chmod(filename, permissions);
|
||||
}
|
||||
|
||||
int UTIL_umask(int mode) {
|
||||
#if PLATFORM_POSIX_VERSION > 0
|
||||
return umask(mode);
|
||||
#else
|
||||
/* do nothing, fake return value */
|
||||
return mode;
|
||||
#endif
|
||||
}
|
||||
|
||||
int UTIL_setFileStat(const char *filename, const stat_t *statbuf)
|
||||
{
|
||||
int res = 0;
|
||||
|
@ -22,7 +22,7 @@ extern "C" {
|
||||
#include "platform.h" /* PLATFORM_POSIX_VERSION, ZSTD_NANOSLEEP_SUPPORT, ZSTD_SETPRIORITY_SUPPORT */
|
||||
#include <stddef.h> /* size_t, ptrdiff_t */
|
||||
#include <sys/types.h> /* stat, utime */
|
||||
#include <sys/stat.h> /* stat, chmod, umask */
|
||||
#include <sys/stat.h> /* stat, chmod */
|
||||
#include "../lib/common/mem.h" /* U64 */
|
||||
|
||||
|
||||
@ -153,11 +153,6 @@ U64 UTIL_getFileSizeStat(const stat_t* statbuf);
|
||||
*/
|
||||
int UTIL_chmod(char const* filename, const stat_t* statbuf, mode_t permissions);
|
||||
|
||||
/**
|
||||
* Wraps umask(). Does nothing when the platform doesn't have that concept.
|
||||
*/
|
||||
int UTIL_umask(int mode);
|
||||
|
||||
/*
|
||||
* In the absence of a pre-existing stat result on the file in question, these
|
||||
* functions will do a stat() call internally and then use that result to
|
||||
|
@ -124,6 +124,23 @@ case "$UNAME" in
|
||||
Darwin | FreeBSD | OpenBSD | NetBSD) MTIME="stat -f %m" ;;
|
||||
esac
|
||||
|
||||
GET_PERMS="stat -c %a"
|
||||
case "$UNAME" in
|
||||
Darwin | FreeBSD | OpenBSD | NetBSD) GET_PERMS="stat -f %Lp" ;;
|
||||
esac
|
||||
|
||||
assertFilePermissions() {
|
||||
STAT1=$($GET_PERMS "$1")
|
||||
STAT2=$2
|
||||
[ "$STAT1" = "$STAT2" ] || die "permissions on $1 don't match expected ($STAT1 != $STAT2)"
|
||||
}
|
||||
|
||||
assertSamePermissions() {
|
||||
STAT1=$($GET_PERMS "$1")
|
||||
STAT2=$($GET_PERMS "$2")
|
||||
[ "$STAT1" = "$STAT2" ] || die "permissions on $1 don't match those on $2 ($STAT1 != $STAT2)"
|
||||
}
|
||||
|
||||
DIFF="diff"
|
||||
case "$UNAME" in
|
||||
SunOS) DIFF="gdiff" ;;
|
||||
@ -192,7 +209,7 @@ println "test : compress to stdout"
|
||||
zstd tmp -c > tmpCompressed
|
||||
zstd tmp --stdout > tmpCompressed # long command format
|
||||
println "test : compress to named file"
|
||||
rm tmpCompressed
|
||||
rm -f tmpCompressed
|
||||
zstd tmp -o tmpCompressed
|
||||
test -f tmpCompressed # file must be created
|
||||
println "test : force write, correct order"
|
||||
@ -346,7 +363,7 @@ rm -f tmplog
|
||||
zstd tmp -f -o "$INTOVOID" 2>&1 | grep -v "Refusing to remove non-regular file"
|
||||
println "test : --rm on stdin"
|
||||
println a | zstd --rm > $INTOVOID # --rm should remain silent
|
||||
rm tmp
|
||||
rm -f tmp
|
||||
zstd -f tmp && die "tmp not present : should have failed"
|
||||
test ! -f tmp.zst # tmp.zst should not be created
|
||||
println "test : -d -f do not delete destination when source is not present"
|
||||
@ -354,7 +371,7 @@ touch tmp # create destination file
|
||||
zstd -d -f tmp.zst && die "attempt to decompress a non existing file"
|
||||
test -f tmp # destination file should still be present
|
||||
println "test : -f do not delete destination when source is not present"
|
||||
rm tmp # erase source file
|
||||
rm -f tmp # erase source file
|
||||
touch tmp.zst # create destination file
|
||||
zstd -f tmp && die "attempt to compress a non existing file"
|
||||
test -f tmp.zst # destination file should still be present
|
||||
@ -368,7 +385,7 @@ println "\n===> decompression only tests "
|
||||
dd bs=1048576 count=1 if=/dev/zero of=tmp
|
||||
zstd -d -o tmp1 "$TESTDIR/golden-decompression/rle-first-block.zst"
|
||||
$DIFF -s tmp1 tmp
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
|
||||
|
||||
println "\n===> compress multiple files"
|
||||
@ -415,7 +432,7 @@ zstd -f tmp*
|
||||
test -f tmp1.zst
|
||||
test -f tmp2.zst
|
||||
test -f tmp3.zst
|
||||
rm tmp1 tmp2 tmp3
|
||||
rm -f tmp1 tmp2 tmp3
|
||||
println "decompress tmp* : "
|
||||
zstd -df ./*.zst
|
||||
test -f tmp1
|
||||
@ -430,7 +447,7 @@ zstd -dc tmpall* > tmpdec
|
||||
test -f tmpdec # should check size of tmpdec (should be 2*(tmp1 + tmp2 + tmp3))
|
||||
println "compress multiple files including a missing one (notHere) : "
|
||||
zstd -f tmp1 notHere tmp2 && die "missing file not detected!"
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
|
||||
|
||||
if [ "$isWindows" = false ] ; then
|
||||
@ -445,6 +462,96 @@ if [ "$isWindows" = false ] ; then
|
||||
rm -rf tmp*
|
||||
fi
|
||||
|
||||
println "\n===> zstd created file permissions tests"
|
||||
if [ "$isWindows" = false ] ; then
|
||||
rm -f tmp1 tmp2 tmp1.zst tmp2.zst tmp1.out tmp2.out # todo: remove
|
||||
|
||||
ORIGINAL_UMASK=$(umask)
|
||||
umask 0000
|
||||
|
||||
datagen > tmp1
|
||||
datagen > tmp2
|
||||
assertFilePermissions tmp1 666
|
||||
assertFilePermissions tmp2 666
|
||||
|
||||
println "test : copy 666 permissions in file -> file compression "
|
||||
zstd -f tmp1 -o tmp1.zst
|
||||
assertSamePermissions tmp1 tmp1.zst
|
||||
println "test : copy 666 permissions in file -> file decompression "
|
||||
zstd -f -d tmp1.zst -o tmp1.out
|
||||
assertSamePermissions tmp1.zst tmp1.out
|
||||
|
||||
rm -f tmp1.zst tmp1.out
|
||||
|
||||
println "test : copy 400 permissions in file -> file compression (write to a read-only file) "
|
||||
chmod 0400 tmp1
|
||||
assertFilePermissions tmp1 400
|
||||
zstd -f tmp1 -o tmp1.zst
|
||||
assertSamePermissions tmp1 tmp1.zst
|
||||
println "test : copy 400 permissions in file -> file decompression (write to a read-only file) "
|
||||
zstd -f -d tmp1.zst -o tmp1
|
||||
assertSamePermissions tmp1.zst tmp1
|
||||
|
||||
rm -f tmp1.zst tmp1.out
|
||||
|
||||
println "test : check created permissions from stdin input in compression "
|
||||
zstd -f -o tmp1.zst < tmp1
|
||||
assertFilePermissions tmp1.zst 666
|
||||
println "test : check created permissions from stdin input in decompression "
|
||||
zstd -f -d -o tmp1.out < tmp1.zst
|
||||
assertFilePermissions tmp1.out 666
|
||||
|
||||
rm -f tmp1.zst tmp1.out
|
||||
|
||||
println "test : check created permissions from multiple inputs in compression "
|
||||
zstd -f tmp1 tmp2 -o tmp1.zst
|
||||
assertFilePermissions tmp1.zst 666
|
||||
println "test : check created permissions from multiple inputs in decompression "
|
||||
cp tmp1.zst tmp2.zst
|
||||
zstd -f -d tmp1.zst tmp2.zst -o tmp1.out
|
||||
assertFilePermissions tmp1.out 666
|
||||
|
||||
rm -f tmp1.zst tmp2.zst tmp1.out tmp2.out
|
||||
|
||||
println "test : check permissions on pre-existing output file in compression "
|
||||
chmod 0600 tmp1
|
||||
touch tmp1.zst
|
||||
chmod 0400 tmp1.zst
|
||||
zstd -f tmp1 -o tmp1.zst
|
||||
assertFilePermissions tmp1.zst 600
|
||||
println "test : check permissions on pre-existing output file in decompression "
|
||||
chmod 0400 tmp1.zst
|
||||
touch tmp1.out
|
||||
chmod 0200 tmp1.out
|
||||
zstd -f -d tmp1.zst -o tmp1.out
|
||||
assertFilePermissions tmp1.out 400
|
||||
|
||||
rm -f tmp1.zst tmp1.out
|
||||
|
||||
umask 0666
|
||||
chmod 0666 tmp1 tmp2
|
||||
|
||||
println "test : respect umask when copying permissions in file -> file compression "
|
||||
zstd -f tmp1 -o tmp1.zst
|
||||
assertFilePermissions tmp1.zst 0
|
||||
println "test : respect umask when copying permissions in file -> file decompression "
|
||||
chmod 0666 tmp1.zst
|
||||
zstd -f -d tmp1.zst -o tmp1.out
|
||||
assertFilePermissions tmp1.out 0
|
||||
|
||||
rm -f tmp1.zst tmp1.out
|
||||
|
||||
println "test : respect umask when compressing from stdin input "
|
||||
zstd -f -o tmp1.zst < tmp1
|
||||
assertFilePermissions tmp1.zst 0
|
||||
println "test : respect umask when decompressing from stdin input "
|
||||
chmod 0666 tmp1.zst
|
||||
zstd -f -d -o tmp1.out < tmp1.zst
|
||||
assertFilePermissions tmp1.out 0
|
||||
|
||||
rm -f tmp1 tmp2 tmp1.zst tmp2.zst tmp1.out tmp2.out
|
||||
umask $ORIGINAL_UMASK
|
||||
fi
|
||||
|
||||
if [ -n "$DEVNULLRIGHTS" ] ; then
|
||||
# these tests requires sudo rights, which is uncommon.
|
||||
@ -667,16 +774,16 @@ $DIFF helloworld.tmp result.tmp
|
||||
ln -s helloworld.zst helloworld.link.zst
|
||||
$EXE_PREFIX ./zstdcat helloworld.link.zst > result.tmp
|
||||
$DIFF helloworld.tmp result.tmp
|
||||
rm zstdcat
|
||||
rm result.tmp
|
||||
rm -f zstdcat
|
||||
rm -f result.tmp
|
||||
println "testing zcat symlink"
|
||||
ln -sf "$ZSTD_BIN" zcat
|
||||
$EXE_PREFIX ./zcat helloworld.zst > result.tmp
|
||||
$DIFF helloworld.tmp result.tmp
|
||||
$EXE_PREFIX ./zcat helloworld.link.zst > result.tmp
|
||||
$DIFF helloworld.tmp result.tmp
|
||||
rm zcat
|
||||
rm ./*.tmp ./*.zstd
|
||||
rm -f zcat
|
||||
rm -f ./*.tmp ./*.zstd
|
||||
println "frame concatenation tests completed"
|
||||
|
||||
|
||||
@ -738,7 +845,7 @@ zstd -d -v -f tmpSparseCompressed -o tmpSparseRegenerated
|
||||
zstd -d -v -f tmpSparseCompressed -c >> tmpSparseRegenerated
|
||||
ls -ls tmpSparse* # look at file size and block size on disk
|
||||
$DIFF tmpSparse2M tmpSparseRegenerated
|
||||
rm tmpSparse*
|
||||
rm -f tmpSparse*
|
||||
|
||||
|
||||
println "\n===> stream-size mode"
|
||||
@ -884,7 +991,7 @@ then
|
||||
println "- Create dictionary with multithreading enabled"
|
||||
zstd --train -T0 "$TESTDIR"/*.c "$PRGDIR"/*.c -o tmpDict
|
||||
fi
|
||||
rm tmp* dictionary
|
||||
rm -f tmp* dictionary
|
||||
|
||||
|
||||
println "\n===> fastCover dictionary builder : advanced options "
|
||||
@ -926,7 +1033,7 @@ zstd -o tmpDict --train-fastcover=k=56,d=8 "$TESTDIR"/*.c "$PRGDIR"/*.c
|
||||
test -f tmpDict
|
||||
zstd --train-fastcover=k=56,d=8 "$TESTDIR"/*.c "$PRGDIR"/*.c
|
||||
test -f dictionary
|
||||
rm tmp* dictionary
|
||||
rm -f tmp* dictionary
|
||||
|
||||
|
||||
println "\n===> legacy dictionary builder "
|
||||
@ -954,7 +1061,7 @@ zstd -o tmpDict --train-legacy "$TESTDIR"/*.c "$PRGDIR"/*.c
|
||||
test -f tmpDict
|
||||
zstd --train-legacy "$TESTDIR"/*.c "$PRGDIR"/*.c
|
||||
test -f dictionary
|
||||
rm tmp* dictionary
|
||||
rm -f tmp* dictionary
|
||||
|
||||
|
||||
println "\n===> integrity tests "
|
||||
@ -1026,7 +1133,7 @@ if [ $GZIPMODE -eq 1 ]; then
|
||||
gzip -t -v tmp.gz
|
||||
gzip -f tmp
|
||||
zstd -d -f -v tmp.gz
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
else
|
||||
println "gzip binary not detected"
|
||||
fi
|
||||
@ -1043,7 +1150,7 @@ if [ $GZIPMODE -eq 1 ]; then
|
||||
zstd -f tmp
|
||||
cat tmp.gz tmp.zst tmp.gz tmp.zst | zstd -d -f -o tmp
|
||||
truncateLastByte tmp.gz | zstd -t > $INTOVOID && die "incomplete frame not detected !"
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
else
|
||||
println "gzip mode not supported"
|
||||
fi
|
||||
@ -1074,7 +1181,7 @@ if [ $LZMAMODE -eq 1 ]; then
|
||||
lzma -Q -f -k --lzma1 tmp
|
||||
zstd -d -f -v tmp.xz
|
||||
zstd -d -f -v tmp.lzma
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
println "Creating symlinks"
|
||||
ln -s "$ZSTD_BIN" ./xz
|
||||
ln -s "$ZSTD_BIN" ./unxz
|
||||
@ -1091,8 +1198,8 @@ if [ $LZMAMODE -eq 1 ]; then
|
||||
./xz -d tmp.xz
|
||||
lzma -Q tmp
|
||||
./lzma -d tmp.lzma
|
||||
rm xz unxz lzma unlzma
|
||||
rm tmp*
|
||||
rm -f xz unxz lzma unlzma
|
||||
rm -f tmp*
|
||||
else
|
||||
println "xz binary not detected"
|
||||
fi
|
||||
@ -1111,7 +1218,7 @@ if [ $LZMAMODE -eq 1 ]; then
|
||||
cat tmp.xz tmp.lzma tmp.zst tmp.lzma tmp.xz tmp.zst | zstd -d -f -o tmp
|
||||
truncateLastByte tmp.xz | zstd -t > $INTOVOID && die "incomplete frame not detected !"
|
||||
truncateLastByte tmp.lzma | zstd -t > $INTOVOID && die "incomplete frame not detected !"
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
else
|
||||
println "xz mode not supported"
|
||||
fi
|
||||
@ -1130,7 +1237,7 @@ if [ $LZ4MODE -eq 1 ]; then
|
||||
lz4 -t -v tmp.lz4
|
||||
lz4 -f -m tmp # ensure result is sent into tmp.lz4, not stdout
|
||||
zstd -d -f -v tmp.lz4
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
else
|
||||
println "lz4 binary not detected"
|
||||
fi
|
||||
@ -1146,7 +1253,7 @@ if [ $LZ4MODE -eq 1 ]; then
|
||||
zstd -f tmp
|
||||
cat tmp.lz4 tmp.zst tmp.lz4 tmp.zst | zstd -d -f -o tmp
|
||||
truncateLastByte tmp.lz4 | zstd -t > $INTOVOID && die "incomplete frame not detected !"
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
else
|
||||
println "\nlz4 mode not supported"
|
||||
fi
|
||||
@ -1180,7 +1287,7 @@ rm -f tmp tmp.tar tmp.tzst tmp.tgz tmp.txz tmp.tlz4 tmp1.zstd
|
||||
datagen > tmp
|
||||
tar cf tmp.tar tmp
|
||||
zstd tmp.tar -o tmp.tzst
|
||||
rm tmp.tar
|
||||
rm -f tmp.tar
|
||||
zstd -d tmp.tzst
|
||||
[ -e tmp.tar ] || die ".tzst failed to decompress to .tar!"
|
||||
rm -f tmp.tar tmp.tzst
|
||||
@ -1259,7 +1366,7 @@ then
|
||||
ZSTD_NBTHREADS=50000000000 zstd -f mt_tmp # numeric value too large, warn and revert to default setting=
|
||||
ZSTD_NBTHREADS=2 zstd -f mt_tmp # correct usage
|
||||
ZSTD_NBTHREADS=1 zstd -f mt_tmp # correct usage: single thread
|
||||
rm mt_tmp*
|
||||
rm -f mt_tmp*
|
||||
|
||||
println "\n===> ovLog tests "
|
||||
datagen -g2MB > tmp
|
||||
@ -1283,7 +1390,7 @@ else
|
||||
println "\n===> no multithreading, skipping zstdmt tests "
|
||||
fi
|
||||
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
|
||||
println "\n===> zstd --list/-l single frame tests "
|
||||
datagen > tmp1
|
||||
@ -1316,9 +1423,9 @@ zstd -f $TEST_DATA_FILE -o $FULL_COMPRESSED_FILE
|
||||
dd bs=1 count=100 if=$FULL_COMPRESSED_FILE of=$TRUNCATED_COMPRESSED_FILE
|
||||
zstd --list $TRUNCATED_COMPRESSED_FILE && die "-l must fail on truncated file"
|
||||
|
||||
rm $TEST_DATA_FILE
|
||||
rm $FULL_COMPRESSED_FILE
|
||||
rm $TRUNCATED_COMPRESSED_FILE
|
||||
rm -f $TEST_DATA_FILE
|
||||
rm -f $FULL_COMPRESSED_FILE
|
||||
rm -f $TRUNCATED_COMPRESSED_FILE
|
||||
|
||||
println "\n===> zstd --list/-l errors when presented with stdin / no files"
|
||||
zstd -l && die "-l must fail on empty list of files"
|
||||
@ -1362,7 +1469,7 @@ zstd -D tmp1 tmp2 -c | zstd --trace tmp.trace -t -D tmp1
|
||||
zstd -b1e10i0 --trace tmp.trace tmp1
|
||||
zstd -b1e10i0 --trace tmp.trace tmp1 tmp2 tmp3
|
||||
|
||||
rm tmp*
|
||||
rm -f tmp*
|
||||
|
||||
|
||||
println "\n===> zstd long distance matching tests "
|
||||
|
Loading…
x
Reference in New Issue
Block a user