]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: cp: --remove-destination must honor the same-file check
authorSylvestre Ledru <sylvestre@debian.org>
Thu, 25 Jun 2026 19:14:00 +0000 (21:14 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 29 Jun 2026 19:42:59 +0000 (20:42 +0100)
* 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
tests/cp/same-file.sh

index cfbcf98adec6b9d47333fef47291d3c480d81469..73b0e6f6479bde7e5610153a6bbe87f8751d3034 100755 (executable)
@@ -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