tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / cp / parent-perm
1 #!/bin/sh
2 # Ensure that cp --parents works properly with a preexisting dest. directory
3
4 # Copyright (C) 2008-2009 Free Software 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
26 working_umask_or_skip_
27
28 mkdir -p a/b/c a/b/d e || framework_failure
29 touch a/b/c/foo a/b/d/foo || framework_failure
30 cp -p --parent a/b/c/foo e || framework_failure
31
32 # Make permissions of e/a different, so that we exercise the
33 # code in cp -p --parents that propagates permissions even
34 # to a destination directory that it doesn't create.
35 chmod g-rx e/a e/a/b || framework_failure
36
37 cp -p --parent a/b/d/foo e || fail=1
38
39 # Ensure that permissions on just-created directory, e/a/,
40 # are the same as those on original, a/.
41
42 # The sed filter maps any 's' from an inherited set-GID bit
43 # to the usual 'x'.  Otherwise, under unusual circumstances, this
44 # test would fail with e.g., drwxr-sr-x != drwxr-xr-x .
45 # For reference, the unusual circumstances is: build dir is set-gid,
46 # so "a/" inherits that.  However, when the user does not belong to
47 # the group of the build directory, chmod ("a/e", 02755) returns 0,
48 # yet fails to set the S_ISGID bit.
49 for dir in a a/b a/b/d; do
50   test $(stat --printf %A $dir|sed s/s/x/g) \
51      = $(stat --printf %A e/$dir|sed s/s/x/g) ||
52   fail=1
53 done
54
55 Exit $fail