mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 11:16:16 +02:00
cp: ensure --attributes-only doesn't remove files
* src/copy.c (copy_internal): Ensure we don't unlink the destination unless explicitly requested. * tests/cp/attr-existing.sh: Add test cases. * NEWS: Mention the bug fix. Fixes https://bugs.gnu.org/40352
This commit is contained in:
@@ -19,11 +19,26 @@
|
||||
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
||||
print_ver_ cp
|
||||
|
||||
printf '1' > file1
|
||||
printf '2' > file2
|
||||
printf '2' > file2.exp
|
||||
printf '1' > file1 || framework_failure_
|
||||
printf '2' > file2 || framework_failure_
|
||||
printf '2' > file2.exp || framework_failure_
|
||||
|
||||
cp --attributes-only file1 file2 || fail=1
|
||||
cmp file2 file2.exp || fail=1
|
||||
|
||||
# coreutils v8.32 and before would remove destination files
|
||||
# if hardlinked or the source was not a regular file.
|
||||
ln file2 link2 || framework_failure_
|
||||
cp -a --attributes-only file1 file2 || fail=1
|
||||
cmp file2 file2.exp || fail=1
|
||||
|
||||
ln -s file1 sym1 || framework_failure_
|
||||
returns_ 1 cp -a --attributes-only sym1 file2 || fail=1
|
||||
cmp file2 file2.exp || fail=1
|
||||
|
||||
# One can still force removal though
|
||||
cp -a --remove-destination --attributes-only sym1 file2 || fail=1
|
||||
test -L file2 || fail=1
|
||||
cmp file1 file2 || fail=1
|
||||
|
||||
Exit $fail
|
||||
|
||||
Reference in New Issue
Block a user