From 1e4dc2e5f1964e453942210fb584135de17d7a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ketelaars?= Date: Tue, 12 Feb 2019 00:03:11 +0100 Subject: [PATCH 1/3] Detect symbolic links on OpenBSD In #1520 it is described that FreeBSD doesn't detect symbolic links. The same is true for OpenBSD. This diff fixes this issue for OpenBSD. I'm guessing that something similar works for FreeBSD as well. However, I'm unable to test this. --- programs/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/util.c b/programs/util.c index 49eea148e..0001cc3d8 100644 --- a/programs/util.c +++ b/programs/util.c @@ -92,6 +92,7 @@ U32 UTIL_isLink(const char* infilename) /* macro guards, as defined in : https://linux.die.net/man/2/lstat */ #ifndef __STRICT_ANSI__ #if defined(_BSD_SOURCE) \ + || defined(__OpenBSD__) \ || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) \ || (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) \ || (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) \ From 482b84f07bd80a917bc8a10a92b2331e680bec56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ketelaars?= Date: Tue, 12 Feb 2019 00:07:32 +0100 Subject: [PATCH 2/3] Make detection of symbolic links more consistent While fixing the detection of symbolic links on OpenBSD I noticed inconsistent behaviour: $ echo hello > hello $ ln -s hello world $ zstd hello world Warning : world is a symbolic link, ignoring hello :316.67% ( 6 => 19 bytes, hello.zst $ ls *.zst hello.zst $ zstd world world :316.67% ( 6 => 19 bytes, world.zst) $ ls *.zst hello.zst world.zst --- programs/zstdcli.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index ef2fe2e91..794e2a811 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -951,6 +951,8 @@ int main(int argCount, const char* argv[]) filenameTable[fileNamesNb++] = filenameTable[u]; } } + if (fileNamesNb == 0 && filenameIdx > 0) + CLEAN_RETURN(1); filenameIdx = fileNamesNb; } if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */ From 77d9109c27959362ea09464cbd17c540406b2cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ketelaars?= Date: Tue, 12 Feb 2019 01:14:58 +0100 Subject: [PATCH 3/3] Add test While here enable symlink test for OpenBSD. --- tests/playTests.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/playTests.sh b/tests/playTests.sh index 6e5582df7..5be065fa8 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -314,18 +314,28 @@ $ECHO foo | $ZSTD > /dev/full && die "write error not detected!" $ECHO "$ECHO foo | $ZSTD | $ZSTD -d > /dev/full" $ECHO foo | $ZSTD | $ZSTD -d > /dev/full && die "write error not detected!" +fi + + +if [ "$isWindows" = false ] && [ "$UNAME" != 'SunOS' ] ; then $ECHO "\n===> symbolic link test " -rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst +rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst $ECHO "hello world" > hello.tmp ln -s hello.tmp world.tmp -$ZSTD world.tmp hello.tmp +ln -s hello.tmp world2.tmp +$ZSTD world.tmp hello.tmp || true test -f hello.tmp.zst # regular file should have been compressed! test ! -f world.tmp.zst # symbolic link should not have been compressed! +$ZSTD world.tmp || true +test ! -f world.tmp.zst # symbolic link should not have been compressed! +$ZSTD world.tmp world2.tmp || true +test ! -f world.tmp.zst # symbolic link should not have been compressed! +test ! -f world2.tmp.zst # symbolic link should not have been compressed! $ZSTD world.tmp hello.tmp -f test -f world.tmp.zst # symbolic link should have been compressed with --force -rm -f hello.tmp world.tmp hello.tmp.zst world.tmp.zst +rm -f hello.tmp world.tmp world2.tmp hello.tmp.zst world.tmp.zst fi