1#!/bin/sh
2
3# Copyright (C) 2000-2023 Free Software Foundation, Inc.
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
18. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
19print_ver_ cp
20
21working_umask_or_skip_
22
23# Run the setgid check from the just-created directory.
24skip_if_setgid_
25
26{
27  mkdir foo bar
28  mkdir -p a/b/c d e g
29  ln -s d/a sym
30  touch f
31} || framework_failure_
32
33# With 4.0.37 and earlier (back to when?), this would fail
34# with the failed assertion from dirname.c due to the trailing slash.
35cp -R --parents foo/ bar || fail=1
36
37# Exercise the make_path and re_protect code in cp.c.
38# FIXME: compare verbose output with expected output.
39cp --verbose -a --parents a/b/c d > /dev/null 2>&1 || fail=1
40test -d d/a/b/c || fail=1
41
42# With 6.7 and earlier, cp --parents f/g d would mistakenly create a
43# directory d/f, even though f is a regular file.
44returns_ 1 cp --parents f/g d 2>/dev/null || fail=1
45test -d d/f && fail=1
46
47# Check that re_protect works.
48chmod go=w d/a || framework_failure_
49cp -a --parents d/a/b/c e || fail=1
50cp -a --parents sym/b/c g || fail=1
51p=$(ls -ld e/d|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
52p=$(ls -ld e/d/a|cut -b-10); case $p in drwx-w--w-);; *) fail=1;; esac
53p=$(ls -ld g/sym|cut -b-10); case $p in drwx-w--w-);; *) fail=1;; esac
54p=$(ls -ld e/d/a/b/c|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
55p=$(ls -ld g/sym/b/c|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
56
57# Before 8.25 cp --parents --no-preserve=mode would copy
58# the mode bits from the source directories
59{
60  mkdir -p np/b &&
61  chmod 0700 np &&
62  touch np/b/file &&
63  chmod 775 np/b/file &&
64  mkdir np_dest
65} || framework_failure_
66cp --parents --no-preserve=mode np/b/file np_dest/ || fail=1
67p=$(ls -ld np_dest/np|cut -b-10); case $p in drwxr-xr-x);; *) fail=1;; esac
68
69# coreutils 9.1-9.3 inclusive would fail to copy acls for absolute dirs
70mkdir dest || framework_failure_
71if test -f /bin/ls; then
72  cp -t dest --parents -p /bin/ls || fail=1
73fi
74
75Exit $fail
76