1002c0cd902a8c610809620ebf3bf257de6ec226
[platform/upstream/coreutils.git] / tests / touch / not-owner
1 #!/bin/sh
2 # Make sure that touch gives reasonable diagnostics when applied
3 # to an unwritable directory owned by some other user.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   touch --version
8 fi
9
10 . $srcdir/../envvar-check
11 . $srcdir/../lang-default
12 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
13
14 test=../../src/test
15 if $test -w /; then
16   echo Skipping because you have write access to /.
17   (exit 77); exit 77
18 fi
19
20 if $test -O / || $test -G /; then
21   echo Skipping because you own /.
22   (exit 77); exit 77
23 fi
24
25 pwd=`pwd`
26 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
27 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
28 trap '(exit $?); exit $?' 1 2 13 15
29
30 framework_failure=0
31 mkdir -p $tmp || framework_failure=1
32 cd $tmp || framework_failure=1
33
34 if test $framework_failure = 1; then
35   echo "$0: failure in testing framework" 1>&2
36   (exit 1); exit 1
37 fi
38
39 fail=0
40
41 # Before fileutils-4.1, we'd get the following misleading
42 # diagnostic instead of `...: Permission denied'.
43 # touch: creating `/': Is a directory
44 touch / > out 2>&1 && fail=1
45
46 # On SunOS4, EPERM is `Not owner'.
47 # On some *BSD systems it's `Operation not permitted'.
48 for msg in 'Not owner' 'Operation not permitted' 'Permission denied'; do
49   cat > exp <<EOF
50 touch: setting times of \`/': $msg
51 EOF
52
53   cmp out exp > /dev/null 2>&1 && { match=1; break; }
54 done
55 test "$match" = 1 || fail=1
56
57 test $fail = 1 && diff out exp 2> /dev/null
58
59 (exit $fail); exit $fail