Tizen 2.0 Release
[external/tizen-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 # Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   touch --version
25 fi
26
27 . $srcdir/../envvar-check
28 . $srcdir/../lang-default
29 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
30
31 test=../../src/test
32 if $test -w /; then
33   echo Skipping because you have write access to /.
34   (exit 77); exit 77
35 fi
36
37 if $test -O / || $test -G /; then
38   echo Skipping because you own /.
39   (exit 77); exit 77
40 fi
41
42 pwd=`pwd`
43 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
44 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
45 trap '(exit $?); exit $?' 1 2 13 15
46
47 framework_failure=0
48 mkdir -p $tmp || framework_failure=1
49 cd $tmp || framework_failure=1
50
51 if test $framework_failure = 1; then
52   echo "$0: failure in testing framework" 1>&2
53   (exit 1); exit 1
54 fi
55
56 fail=0
57
58 # Before fileutils-4.1, we'd get the following misleading
59 # diagnostic instead of `...: Permission denied'.
60 # touch: creating `/': Is a directory
61 touch / > out 2>&1 && fail=1
62
63 # On SunOS4, EPERM is `Not owner'.
64 # On some *BSD systems it's `Operation not permitted'.
65 for msg in 'Not owner' 'Operation not permitted' 'Permission denied'; do
66   cat > exp <<EOF
67 touch: setting times of \`/': $msg
68 EOF
69
70   cmp out exp > /dev/null 2>&1 && { match=1; break; }
71 done
72 test "$match" = 1 || fail=1
73
74 test $fail = 1 && diff out exp 2> /dev/null
75
76 (exit $fail); exit $fail