]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: mv: check cross-fs replacement with special files
authorPádraig Brady <P@draigBrady.com>
Thu, 25 Jun 2026 20:03:00 +0000 (22:03 +0200)
committerPádraig Brady <P@draigBrady.com>
Tue, 30 Jun 2026 18:04:23 +0000 (19:04 +0100)
* tests/mv/mv-special-1.sh: Moving a socket onto an existing file
on another file system must replace that file, and not for example
unlink the destination first and then fail, leaving the user
with neither file.

Link: https://github.com/coreutils/coreutils/pull/303
tests/mv/mv-special-1.sh

index fccdf6eee28e7834ffb4e77ee5f66731ffd847d8..44f78fe59fca9bc6aeca84973e7c14beb192ea09 100755 (executable)
@@ -80,4 +80,21 @@ compare exp out2 || fail=1
 # cd "$other_partition_tmpdir"
 # ls -l -A -R "$other_partition_tmpdir"
 
+# Moving a special file across file systems onto an existing destination
+# must replace that destination, not unlink it first and then fail,
+# leaving the user with neither file.
+source=mv-sock
+if python -c "import socket as s; \
+              s.socket(s.AF_UNIX).bind('$source'); \
+              s.socket(s.AF_UNIX).bind('$other_partition_tmpdir/test.sock') \
+              " &&
+ test -S "$source" && test -S "$other_partition_tmpdir/test.sock"; then
+
+  dest="$other_partition_tmpdir/mv-sock-dest"
+  touch "$dest" || framework_failure_
+  mv "$source" "$dest" || fail=1
+  test -S "$dest" || fail=1       # destination replaced by the socket
+  test -e "$source" && fail=1     # source removed
+fi
+
 Exit $fail