1#!/bin/sh 2# Ensure that cp --parents works properly with a preexisting dest. directory 3 4# Copyright (C) 2008-2023 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 <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ cp 21 22working_umask_or_skip_ 23# cp -p gives ENOTSUP on NFS on Linux 2.6.9 at least 24require_local_dir_ 25 26mkdir -p a/b/c a/b/d e || framework_failure_ 27touch a/b/c/foo a/b/d/foo || framework_failure_ 28cp -p --parent a/b/c/foo e || framework_failure_ 29 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. 33chmod g-rx e/a e/a/b || framework_failure_ 34 35cp -p --parent a/b/d/foo e || fail=1 36 37# Ensure that permissions on just-created directory, e/a/, 38# are the same as those on original, a/. 39 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. 47for 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 51done 52 53Exit $fail 54