e66a577844f685de51b6fad6b2833cb3409c215f
[platform/upstream/coreutils.git] / tests / chgrp / no-x
1 #!/bin/sh
2 # Make sure chgrp gives the right diagnostic for a readable,
3 # but inaccessible directory.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   chgrp --version
8 fi
9
10 . $srcdir/../group-names
11 set _ $groups; shift
12 g1=$1
13 g2=$2
14
15 . $srcdir/../lang-default
16 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
17
18 pwd=`pwd`
19 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
20 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
21 trap '(exit $?); exit $?' 1 2 13 15
22
23 framework_failure=0
24 mkdir -p $tmp || framework_failure=1
25 cd $tmp || framework_failure=1
26 mkdir -p d/no-x/y || framework_failure=1
27 chmod u=rw d/no-x || framework_failure=1
28
29 if test $framework_failure = 1; then
30   echo "$0: failure in testing framework" 1>&2
31   (exit 1); exit 1
32 fi
33
34 fail=0
35
36 # This must exit nonzero.
37 chgrp -R $g2 d >/dev/null 2>out && fail=1
38 cat <<\EOF > exp
39 chgrp: `d/no-x': Permission denied
40 EOF
41
42 # With native fdopendir, du uses a different code path.
43 cat <<\EOF > exp-native-fdopendir
44 chgrp: cannot access `d/no-x/y': Permission denied
45 chgrp: fts_read failed: Permission denied
46 EOF
47
48 if cmp out exp >/dev/null 2>&1; then
49   :
50 else
51   if cmp out exp-native-fdopendir; then
52     :
53   else
54     fail=1
55   fi
56 fi
57
58 test $fail = 1 && diff out exp 2> /dev/null
59
60 (exit $fail); exit $fail