summaryrefslogtreecommitdiff
path: root/tests/mv/i-4.sh
diff options
context:
space:
mode:
authorBoris Ranto <branto@redhat.com>2014-11-18 20:20:50 +0100
committerPádraig Brady <P@draigBrady.com>2014-11-21 02:48:45 +0000
commit222d7ac0c4f5f005438c534f3aba62fd94d96dc2 (patch)
tree55263d170dd91118391d3fddd0598311f33d43d7 /tests/mv/i-4.sh
parentf43c072a04ba881debf35ccdb509ee0a145b255c (diff)
downloadcoreutils-222d7ac0c4f5f005438c534f3aba62fd94d96dc2.tar.xz
mv: fail when moving a file to a hardlink
We may run into a race condition if we treat hard links to the same file as distinct files. If we do 'mv a b' and 'mv b a' in parallel, both a and b can disappear from the file system. The reason is that in this case the unlink on src is called and the system calls can end up being run in the order where unlink(a) and unlink(b) are the last two system calls. Therefore exit with an error code so that we avoid the potential data loss. * src/copy.c (same_file_ok): Don't set unlink_src that was used by mv, and return false for two hardlinks to a file in move_mode. *src/copy.c (copy_internal): No longer honor the unlink_src option, used only by mv. NEWS: Mention the change in behavior. * tests/cp/same-file.sh: Augment to cover the `cp -a hlsl1 sl1` case. * tests/mv/hard-verbose.sh: Remove no longer needed test. * tests/local.mk: Remove the reference to hard-verbose.sh. * tests/mv/hard-4.sh: Adjust so we fail in this case. * tests/mv/i-4.sh: Likewise. * tests/mv/symlink-onto-hardlink-to-self.sh: Likewise.
Diffstat (limited to 'tests/mv/i-4.sh')
-rwxr-xr-xtests/mv/i-4.sh14
1 files changed, 6 insertions, 8 deletions
diff --git a/tests/mv/i-4.sh b/tests/mv/i-4.sh
index b366bc46e..ad79389d8 100755
--- a/tests/mv/i-4.sh
+++ b/tests/mv/i-4.sh
@@ -23,6 +23,7 @@ for i in a b; do
echo $i > $i || framework_failure_
done
echo y > y || framework_failure_
+echo n > n || framework_failure_
mv -i a b < y >/dev/null 2>&1 || fail=1
@@ -32,18 +33,15 @@ case "$(cat b)" in
*) fail=1 ;;
esac
-# Ensure that mv -i a b works properly with 'n' and 'y'
-# responses, even when a and b are hard links to the same file.
-# This 'n' test would fail (no prompt) for coreutils-5.0.1 through 5.3.0.
-echo n > n
+# Ensure that mv -i a b works properly with 'n' and 'y' responses,
+# when a and b are hard links to the same file.
rm -f a b
echo a > a
ln a b
-mv -i a b < n >/dev/null 2>&1 || fail=1
+mv -i a b < y 2>err && fail=1
test -r a || fail=1
test -r b || fail=1
-mv -i a b < y >/dev/null 2>&1 || fail=1
-test -r a && fail=1
-test -r b || fail=1
+printf "mv: 'a' and 'b' are the same file\n" > exp
+compare exp err || fail=1
Exit $fail