mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-20 10:51:48 +02:00
When recursively copying files into OS trees, it often happens that some subdirectory of the source directory is a symlink in the target directory. Currently, cp will fail in that scenario with the error: "cannot overwrite non-directory %s with directory %s" However, we'd like cp in this scenario to follow the destination directory symlink and copy the files into the symlinked directory instead. Let's support this by adding a new option --keep-directory-symlink that makes cp follow destination directory symlinks. We name the option --keep-directory-symlink to keep consistent with tar which has the same option with the same effect. * doc/coreutils.texi (cp invocation): Describe the new option. * src/copy.h: Add the new setting. * src/copy.h: Adjust to follow symlinks if setting enabled. * src/cp.c (usage): Describe the new option. (main): Accept the new option. * tests/cp/keep-directory-symlink.sh: A new test. * tests/local.mk: Reference the new test. * NEWS: Mention the new feature.
28 lines
1016 B
Bash
Executable File
28 lines
1016 B
Bash
Executable File
#!/bin/sh
|
|
# Test that cp --keep-directory-symlink follows symlinks.
|
|
|
|
# Copyright (C) 2024 Free Software Foundation, Inc.
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
|
print_ver_ cp
|
|
|
|
mkdir -p a/b b/d/e || framework_failure_
|
|
ln -s b a/d || framework_failure_
|
|
|
|
cp -RT --copy-contents b a || fail=1
|
|
cp -RT --copy-contents --keep-directory-symlink b a || fail=1
|
|
ls a/b/e || fail=1
|