build: ensure sys/select.h is included
[coreutils.git] / tests / mv / symlink-onto-hardlink-to-self.sh
blobac1463c9073c781b23ce4a824f1c0fb2de1356f3
1 #!/bin/sh
2 # Demonstrate that when moving a symlink onto a hardlink-to-that-symlink,
3 # an error is presented. 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-2019 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 <https://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 # Attempt to create a hard link to that symlink.
30 # On some systems, it's not possible: they create a hard link to the referent.
31 ln s2 s1 || framework_failure_
33 # If s1 is not a symlink, skip this test.
34 test -h s1 \
35 || skip_ your kernel or file system cannot create a hard link to a symlink
37 for opt in '' --backup; do
39 if test "$opt" = --backup; then
40 mv $opt s1 s2 > out 2>&1 || fail=1
41 compare /dev/null out || fail=1
43 # Ensure that s1 is gone.
44 test -e s1 && fail=1
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 echo "mv: 's1' and 's2' are the same file" > exp
51 mv $opt s1 s2 2>err && fail=1
52 compare exp err || fail=1
54 # Ensure that s1 is still present.
55 test -e s1 || fail=1
57 # Without --backup, ensure there is no backup file.
58 test -e s2~ && fail=1
61 done
63 Exit $fail