tests: avoid a race in tail --retry testing
[coreutils.git] / tests / mv / symlink-onto-hardlink-to-self.sh
blob1e2bf817171a139bca2d15220148e96b3d2bb4a4
1 #!/bin/sh
2 # Demonstrate that when moving a symlink onto a hardlink-to-that-symlink, the
3 # source symlink is removed. Depending on your kernel (e.g., Linux, Solaris,
4 # but not NetBSD), prior to coreutils-8.16, the mv would successfully perform
5 # a no-op. I.e., surprisingly, mv s1 s2 would succeed, yet fail to remove s1.
7 # Copyright (C) 2012-2013 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23 print_ver_ mv
25 # Create a file f, and a symlink s1 to that file.
26 touch f || framework_failure_
27 ln -s f s2 || framework_failure_
29 for opt in '' --backup; do
31 # Attempt to create a hard link to that symlink.
32 # On some systems, it's not possible: they create a hard link to the referent.
33 ln s2 s1 || framework_failure_
35 # If s1 is not a symlink, skip this test.
36 test -h s1 \
37 || skip_ your kernel or file system cannot create a hard link to a symlink
39 mv $opt s1 s2 > out 2>&1 || fail=1
40 compare /dev/null out || fail=1
42 # Ensure that s1 is gone.
43 test -e s1 && fail=1
45 if test "$opt" = --backup; then
46 # With --backup, ensure that the backup file was created.
47 ref=$(readlink s2~) || fail=1
48 test "$ref" = f || fail=1
49 else
50 # Without --backup, ensure there is no backup file.
51 test -e s2~ && fail=1
54 done
56 Exit $fail