Various platforms ignore the sticky bit when given to the mode
argument of mkdir. This patch tries to check the behavior using Perl,
which won't execute [lf]chmod like 'mkdir -m' will, or accepts either
mode if it cannot be executed.
-- 8< --
* init.cfg (have_perl_): New function based on require_perl_.
(require_perl_): Use it.
* tests/cp/special-bits.sh: Check if the mkdir system call sets sticky
bits. Adjust the expected mode of created directories accordingly.
---
init.cfg | 11 ++++++++---
tests/cp/special-bits.sh | 20 ++++++++++++++++----
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/init.cfg b/init.cfg
index 7ed892ed8..09e13a54a 100644
--- a/init.cfg
+++ b/init.cfg
@@ -673,12 +673,17 @@ require_dirent_d_type_()
|| skip_ requires d_type support
}
+# Check if we have Perl.
+have_perl_()
+{
+ : ${PERL=perl}
+ $PERL -e 'use warnings' > /dev/null 2>&1
+}
+
# Skip the current test if we lack Perl.
require_perl_()
{
- : ${PERL=perl}
- $PERL -e 'use warnings' > /dev/null 2>&1 \
- || skip_ 'configure did not find a usable version of Perl'
+ have_perl_ || skip_ 'configure did not find a usable version of Perl'
}
# Does the current (working-dir) file system support sparse files?
diff --git a/tests/cp/special-bits.sh b/tests/cp/special-bits.sh
index 0c4973a92..73dc30702 100755
--- a/tests/cp/special-bits.sh
+++ b/tests/cp/special-bits.sh
@@ -77,6 +77,18 @@ for opt in --recursive --parents; do
case $p3 in dr-xr-xr-x*) ;; *) fail=1 ;; esac
done
+# Test whether the mkdir system call sets the sticky bit when given
+# in the mode argument.
+have_perl_ && $PERL -e 'umask 0; mkdir "sticky", 01777 or die "$!\n"' && {
+ if test -k sticky; then
+ sticky=t
+ else
+ sticky=x
+ fi
+}
+test -z "$sticky" && sticky=[xt]
+rm -rf sticky || framework_failure_
+
# Test the behavior when --preserve=ownership is used.
for opt in --recursive --parents; do
rm -rf dst dst2 &&
@@ -89,15 +101,15 @@ for opt in --recursive --parents; do
cp --preserve=ownership $opt $src dst || fail=1
set _ $(ls -ld dst/d); shift; p2=$1
set _ $(ls -ld dst/d/e); shift; p3=$1
- case $p2 in dr-xr-xr-t*) ;; *) fail=1 ;; esac
- case $p3 in dr-xr-xr-t*) ;; *) fail=1 ;; esac
+ case $p2 in dr-xr-xr-$sticky*) ;; *) fail=1 ;; esac
+ case $p3 in dr-xr-xr-$sticky*) ;; *) fail=1 ;; esac
chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
cp --preserve=ownership $opt $src dst2 || fail=1
set _ $(ls -ld dst2/d); shift; p2=$1
set _ $(ls -ld dst2/d/e); shift; p3=$1
- case $p2 in dr-xr-xr-t*) ;; *) fail=1 ;; esac
- case $p3 in dr-xr-xr-t*) ;; *) fail=1 ;; esac
+ case $p2 in dr-xr-xr-$sticky*) ;; *) fail=1 ;; esac
+ case $p3 in dr-xr-xr-$sticky*) ;; *) fail=1 ;; esac
done
Exit $fail
--
2.56.1