From: Sylvestre Ledru Date: Thu, 25 Jun 2026 19:14:00 +0000 (+0200) Subject: tests: cp: --remove-destination must honor the same-file check X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0eb2fff6130a37770b6b66cb91d680a2f600d1da;p=thirdparty%2Fcoreutils.git tests: cp: --remove-destination must honor the same-file check * tests/cp/same-file.sh: A different spelling of the same path ('foo' vs './foo') must still be detected as the same file, so --remove-destination refuses instead of unlinking the source. Link: https://github.com/coreutils/coreutils/pull/302 --- diff --git a/tests/cp/same-file.sh b/tests/cp/same-file.sh index cfbcf98ade..73b0e6f647 100755 --- a/tests/cp/same-file.sh +++ b/tests/cp/same-file.sh @@ -252,4 +252,16 @@ exec 1>&3 3>&- compare expected actual 1>&2 || fail=1 +# The "same file" check must compare inode/device, not the path string: +# 'foo' and './foo' name the same file, so --remove-destination has to +# refuse rather than unlink the destination (which is also the source) +# and lose the data. +rm -rf dir; mkdir dir; cd dir || framework_failure_ +echo "$contents" > foo || framework_failure_ +returns_ 1 cp --remove-destination foo ./foo 2> err || fail=1 +grep -F 'are the same file' err || { cat err; fail=1; } +test -f foo || fail=1 +test "$(cat foo)" = "$contents" || fail=1 +cd .. + Exit $fail