[fileio] Refuse to remove non-regular file
This commit is contained in:
parent
04a1557e28
commit
82bc8fe0cc
@ -261,6 +261,10 @@ void FIO_setLdmHashEveryLog(unsigned ldmHashEveryLog) {
|
|||||||
* @result : Unlink `fileName`, even if it's read-only */
|
* @result : Unlink `fileName`, even if it's read-only */
|
||||||
static int FIO_remove(const char* path)
|
static int FIO_remove(const char* path)
|
||||||
{
|
{
|
||||||
|
if (!UTIL_isRegularFile(path)) {
|
||||||
|
DISPLAYLEVEL(2, "zstd: Refusing to remove non-regular file %s\n", path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
/* windows doesn't allow remove read-only files,
|
/* windows doesn't allow remove read-only files,
|
||||||
* so try to make it writable first */
|
* so try to make it writable first */
|
||||||
@ -314,9 +318,13 @@ static FILE* FIO_openDstFile(const char* dstFileName)
|
|||||||
g_sparseFileSupport = ZSTD_SPARSE_DEFAULT;
|
g_sparseFileSupport = ZSTD_SPARSE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (dstFileName, nulmark)) { /* not /dev/null */
|
if (UTIL_isRegularFile(dstFileName)) {
|
||||||
|
FILE* fCheck;
|
||||||
|
if (!strcmp(dstFileName, nulmark)) {
|
||||||
|
EXM_THROW(40, "%s is unexpectedly a regular file", dstFileName);
|
||||||
|
}
|
||||||
/* Check if destination file already exists */
|
/* Check if destination file already exists */
|
||||||
FILE* const fCheck = fopen( dstFileName, "rb" );
|
fCheck = fopen( dstFileName, "rb" );
|
||||||
if (fCheck != NULL) { /* dst file exists, authorization prompt */
|
if (fCheck != NULL) { /* dst file exists, authorization prompt */
|
||||||
fclose(fCheck);
|
fclose(fCheck);
|
||||||
if (!g_overwrite) {
|
if (!g_overwrite) {
|
||||||
|
@ -56,10 +56,12 @@ fi
|
|||||||
|
|
||||||
isWindows=false
|
isWindows=false
|
||||||
INTOVOID="/dev/null"
|
INTOVOID="/dev/null"
|
||||||
|
DEVDEVICE="/dev/zero"
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
Windows*)
|
Windows*)
|
||||||
isWindows=true
|
isWindows=true
|
||||||
INTOVOID="NUL"
|
INTOVOID="NUL"
|
||||||
|
DEVDEVICE="NUL"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -159,6 +161,12 @@ $ZSTD -f --rm tmp
|
|||||||
test ! -f tmp # tmp should no longer be present
|
test ! -f tmp # tmp should no longer be present
|
||||||
$ZSTD -f -d --rm tmp.zst
|
$ZSTD -f -d --rm tmp.zst
|
||||||
test ! -f tmp.zst # tmp.zst should no longer be present
|
test ! -f tmp.zst # tmp.zst should no longer be present
|
||||||
|
$ECHO "test : should quietly not remove non-regular file"
|
||||||
|
$ECHO hello > tmp
|
||||||
|
$ZSTD tmp -f -o "$DEVDEVICE" 2>tmplog > "$INTOVOID"
|
||||||
|
grep -v "Refusing to remove non-regular file" tmplog
|
||||||
|
rm -f tmplog
|
||||||
|
$ZSTD tmp -f -o "$INTONULL" 2>&1 | grep -v "Refusing to remove non-regular file"
|
||||||
$ECHO "test : --rm on stdin"
|
$ECHO "test : --rm on stdin"
|
||||||
$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
|
$ECHO a | $ZSTD --rm > $INTOVOID # --rm should remain silent
|
||||||
rm tmp
|
rm tmp
|
||||||
|
Loading…
Reference in New Issue
Block a user