79d691676d51fc7dda4978542f8e680cf8e1d755
[platform/upstream/coreutils.git] / tests / rm / inaccessible
1 #!/bin/sh
2 # Ensure that rm works even when run from a directory
3 # for which the user has no access at all.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   rm --version
8 fi
9
10 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
11 . $srcdir/../lang-default
12
13 # Skip this test if your system has neither the openat-style functions
14 # nor /proc/self/fd support with which to emulate them.
15 skip=yes
16 grep '^#define HAVE_OPENAT' $top_srcdir/config.h > /dev/null && skip=no
17 test -d /proc/self/fd && skip=no
18 if test $skip = yes; then
19   echo 1>&2 "$0: no openat support, so skipping this test"
20   (exit 77); exit 77
21 fi
22
23 pwd=`pwd`
24 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
25 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
26 trap '(exit $?); exit $?' 1 2 13 15
27
28 framework_failure=0
29 mkdir -p $tmp || framework_failure=1
30 cd $tmp || framework_failure=1
31 mkdir abs1 abs2 no-access || framework_failure=1
32
33 if test $framework_failure = 1; then
34   echo "$0: failure in testing framework" 1>&2
35   (exit 1); exit 1
36 fi
37
38 fail=0
39
40 p=$pwd/$tmp
41 set +x
42 (cd no-access; chmod 0 . && rm -r $p/abs1 rel $p/abs2) 2> out && fail=1
43 test -d $p/abs1 && fail=1
44 test -d $p/abs2 && fail=1
45
46 cat <<\EOF > exp || fail=1
47 rm: cannot remove `rel': Permission denied
48 EOF
49
50 # AIX 4.3.3 fails with a different diagnostic.
51 # Transform their diagnostic
52 #   ...: The file access permissions do not allow the specified action.
53 # to the expected one:
54 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
55
56 cmp out exp || fail=1
57 test $fail = 1 && diff out exp 2> /dev/null
58
59 (exit $fail); exit $fail