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
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.
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.
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
50 # Without --backup, ensure there is no backup file.