tests: cp: check -rT does not copy through a symlinked destination

* tests/cp/r-T-symlink.sh: New test.  Ensure cp -rT refuses to copy
a directory over a symlink to a directory, while a trailing slash or
omitting -T copies into what the symlink resolves to.
* tests/local.mk (all_tests): Reference the new test.
https://github.com/uutils/coreutils/pull/14993

Link: https://github.com/coreutils/coreutils/pull/398
This commit is contained in:
Sylvestre Ledru authored and Pádraig Brady committed 2026-10-25 13:43:13 +00:00
1 parent 0445daffd6
commit af626a5749
2 files changed
+48

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
#!/bin/sh
# Ensure cp -rT doesn't copy through a destination symlink to a directory.
# Copyright (C) 2026 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 src dir &&
touch src/file &&
ln -s dir dst || framework_failure_
# With -T, the symlink itself is the destination and is not replaced.
returns_ 1 cp -rT src dst 2>err || fail=1
cat <<\EOF > exp || framework_failure_
cp: cannot overwrite non-directory 'dst' with directory 'src'
EOF
compare exp err || fail=1
test -h dst || fail=1
test -e dir/file && fail=1
# With a trailing slash the symlink is followed.
cp -rT src dst/ || fail=1
test -f dir/file || fail=1
rm dir/file || framework_failure_
# Without -T, the copy goes into the directory the symlink resolves to.
cp -r src/. dst || fail=1
test -f dir/file || fail=1
cp -r src dst || fail=1
test -f dir/src/file || fail=1
test -h dst || fail=1
Exit $fail
+1
View File
@@ -620,6 +620,7 @@ all_tests = \
tests/cp/preserve-slink-time.sh \
tests/cp/proc-short-read.sh \
tests/cp/proc-zero-len.sh \
tests/cp/r-T-symlink.sh \
tests/cp/r-vs-symlink.sh \
tests/cp/readonly-dir.sh \
tests/cp/reflink-auto.sh \