cp: add --keep-directory-symlink option
commita357cfb021cc0ecaff1de81014271977ce1502e7
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 25 Jan 2024 13:02:32 +0000 (25 14:02 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 22 Feb 2024 14:37:47 +0000 (22 14:37 +0000)
treeb7fe6b418bb5b8f713c73ffd78d2e99e7bd72da2
parente82af7c2e698c42626cc4107d94c3e0b749f497e
cp: add --keep-directory-symlink option

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.
NEWS
doc/coreutils.texi
src/copy.c
src/copy.h
src/cp.c
tests/cp/keep-directory-symlink.sh [new file with mode: 0755]
tests/local.mk