maint: add a syntax check to prevent use of NULL
[coreutils.git] / tests / cp / parent-perm.sh
bloba79164eebf3520d28167f593d72696284a7f9f43
1 #!/bin/sh
2 # Ensure that cp --parents works properly with a preexisting dest. directory
4 # Copyright (C) 2008-2023 Free Software Foundation, Inc.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cp
22 working_umask_or_skip_
23 # cp -p gives ENOTSUP on NFS on Linux 2.6.9 at least
24 require_local_dir_
26 mkdir -p a/b/c a/b/d e || framework_failure_
27 touch a/b/c/foo a/b/d/foo || framework_failure_
28 cp -p --parent a/b/c/foo e || framework_failure_
30 # Make permissions of e/a different, so that we exercise the
31 # code in cp -p --parents that propagates permissions even
32 # to a destination directory that it doesn't create.
33 chmod g-rx e/a e/a/b || framework_failure_
35 cp -p --parent a/b/d/foo e || fail=1
37 # Ensure that permissions on just-created directory, e/a/,
38 # are the same as those on original, a/.
40 # The sed filter maps any 's' from an inherited set-GID bit
41 # to the usual 'x'. Otherwise, under unusual circumstances, this
42 # test would fail with e.g., drwxr-sr-x != drwxr-xr-x .
43 # For reference, the unusual circumstances is: build dir is set-gid,
44 # so "a/" inherits that. However, when the user does not belong to
45 # the group of the build directory, chmod ("a/e", 02755) returns 0,
46 # yet fails to set the S_ISGID bit.
47 for dir in a a/b a/b/d; do
48 test $(stat --printf %A $dir|sed s/s/x/g) \
49 = $(stat --printf %A e/$dir|sed s/s/x/g) ||
50 fail=1
51 done
53 Exit $fail