doc: move @shortcontents and @contents from end to start
[platform/upstream/coreutils.git] / tests / cp / fail-perm
1 #!/bin/sh
2
3 # Copyright (C) 2000, 2002-2008 Free Software
4 # Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   cp --version
22 fi
23
24 . $srcdir/test-lib.sh
25 skip_if_root_
26
27 chmod g-s . || framework_failure
28 mkdir D D/D || framework_failure
29 touch D/a || framework_failure
30 chmod 0 D/a || framework_failure
31 chmod u=rx,go=,-st D || framework_failure
32
33 fail=0
34
35 # This is expected to exit non-zero, because it can't read D/a.
36 cp -pR D DD > /dev/null 2>&1 && fail=1
37
38 # Permissions on DD must be `dr-x------'
39
40 mode=`ls -ld DD|cut -b-10`
41 test "$mode" = dr-x------ || fail=1
42
43 chmod 0 D
44 ln -s D/D symlink
45 touch F
46 cat > exp <<\EOF
47 cp: accessing `symlink': Permission denied
48 EOF
49
50 cp F symlink 2> out && fail=1
51 # HPUX appears to fail with EACCES rather than EPERM.
52 # Transform their diagnostic
53 #   ...: The file access permissions do not allow the specified action.
54 # to the expected one:
55 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
56 compare out exp || fail=1
57
58 cp --target-directory=symlink F 2> out && fail=1
59 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
60 compare out exp || fail=1
61
62 chmod 700 D
63
64 Exit $fail