--- /dev/null 2005-04-10 23:52:41.000000000 +0100 +++ tests/chmod/symlinks 2005-07-17 11:57:29.974020711 +0100 @@ -0,0 +1,99 @@ +#!/bin/sh +# Make sure chmod options -H, -L, -P work as designed. +# This is a feature from BSD's chmod. + +if test "$VERBOSE" = yes; then + set -x + chmod --version +fi + +pwd=`pwd` +tmp=equals.$$ +trap 'status=$?; cd $pwd; rm -rf A B C && exit $status' 0 +trap '(exit $?); exit' 1 2 13 15 + +framework_failure=0 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +fail=0 + +# prepare our files. +mkdir A B +ln -s B C +( cd B ; ln -s ../A b ) +touch A/xyzzy B/xyzzy +chmod 555 A/xyzzy B/xyzzy + +expected_yes=-r-xr-x--- +expected_no=-r-xr-xr-x + +if test $fail -eq 0; then + : 1 + # Test -P (the default). + # B should be unaffected since c->B should not be followed. + chmod -R -P o= A C || fail=1 + + # -P: A should be affected. B should be unaffected + set _ `ls -l A/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_yes" || fail=1 + set _ `ls -l B/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_no" || fail=1 +fi + +if test $fail -eq 0; then + : 2 + # reset to initial conditions. + chmod -R 555 */xyzzy + + # -L: Both A and B should be affected, because + # chmod should follow the link B/b -> ../A + chmod -R -L o= B || fail=1 + set _ `ls -l A/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_yes" || fail=1 + set _ `ls -l B/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_yes" || fail=1 +fi + +if test $fail -eq 0; then + : 3a + # reset to initial conditions. + chmod -R 555 */xyzzy + + # -H: Only links named on the command line should + # be followed. + chmod -R -H o= C || fail=1 + # B/xyzzy should be affected since C is a symlink to A. + set _ `ls -l B/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_yes" || fail=1 +fi + +if test $fail -eq 0; then + : 3b + # reset to initial conditions. + chmod -R 555 */xyzzy + chmod -R -H o= B || fail=1 + # A/xyzzy should NOT be affected since the B/b symlink + # should not be affected. + set _ `ls -l A/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_no" || fail=1 +fi + +if test $fail -eq 0; then + : 4 + # Check that the default behaviour is consistent with -P. + # reset to initial conditions. + chmod -R 555 */xyzzy + chmod -R -P o= A C || fail=1 + + # -P: A should be affected. B should be unaffected + set _ `ls -l A/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_yes" || fail=1 + set _ `ls -l B/xyzzy`; shift; actual_perms=$1 + test "$actual_perms" = "$expected_no" || fail=1 +fi + +(exit $fail); exit $fail