7cd1648e2792f7e1946f19e4e28abc566320ec76
[platform/upstream/coreutils.git] / tests / chgrp / recurse
1 #!/bin/sh
2 # ad-hoc tests of chgrp with -R and -H or -L and symlinks
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   chgrp --version
7 fi
8
9 . $srcdir/../group-names
10
11 pwd=`pwd`
12 tmp=recurse.$$
13 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
14 trap '(exit $?); exit' 1 2 13 15
15
16 framework_failure=0
17 mkdir $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19
20 if test $framework_failure = 1; then
21   echo 'failure in testing framework' 1>&2
22   (exit 1); exit 1
23 fi
24
25 set _ $groups; shift
26 g1=$1
27 g2=$2
28
29 fail=0
30
31 # chgrp -R should not traverse a symlink to a directory.
32 mkdir d e
33 touch d/dd e/ee
34 ln -s ../e d/s
35 chgrp -R $g1 e/ee || fail=1
36 # This should not should change the group of e/ee
37 chgrp -R $g2 d
38 set _ `ls -ln e/ee`; g=$5; test "$g" = $g1 || fail=1
39 # This must change the group of e/ee, since -L makes
40 # chgrp traverse the symlink from d/s into e.
41 chgrp -L -R $g2 d
42 set _ `ls -ln e/ee`; g=$5; test "$g" = $g2 || fail=1
43
44 # This must *not* change the group of e/ee
45 chgrp -H -R $g1 d
46 set _ `ls -ln e/ee`; g=$5; test "$g" = $g2 || fail=1
47
48 ln -s d link
49
50 # This shouldn't change the group of e/ee either.
51 chgrp -H -R $g1 link || fail=1
52 set _ `ls -ln e/ee`; g=$5; test "$g" = $g2 || fail=1
53 # But it *should* change d/dd.
54 set _ `ls -ln d/dd`; g=$5; test "$g" = $g1 || fail=1
55
56 (exit $fail); exit $fail