2 # Miscellaneous tests for "ln".
4 # Copyright (C) 1998-2000, 2004, 2006-2007 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if test "$VERBOSE" = yes; then
24 .
$srcdir/..
/test-lib.sh
28 ld
=tln-symlink-to-subdir
32 # Create a simple symlink with both source and destination files
33 # in current directory.
34 touch $f || framework_failure
35 rm -f $t || framework_failure
40 # Create a symlink with source file and explicit destination directory/file.
41 touch $f || framework_failure
42 rm -rf $d || framework_failure
43 mkdir
$d || framework_failure
44 ln -s ..
/$f $d/$t || fail
=1
45 test -f $d/$t || fail
=1
48 # Create a symlink with source file and destination directory.
49 touch $f || framework_failure
50 rm -rf $d || framework_failure
51 mkdir
$d || framework_failure
52 ln -s ..
/$f $d || fail
=1
53 test -f $d/$f || fail
=1
56 # See whether a trailing slash is followed too far.
57 touch $f || framework_failure
58 rm -rf $d || framework_failure
59 mkdir
$d $d/$f || framework_failure
60 ln $f $d/ 2> /dev
/null
&& fail
=1
61 ln -s $f $d/ 2> /dev
/null
&& fail
=1
64 # Make sure we get a failure with existing dest without -f option
65 touch $t || framework_failure
66 # FIXME: don't ignore the error message but rather test
67 # it to make sure it's the right one.
68 ln -s $t $t 2> /dev
/null
&& fail
=1
71 # Make sure -sf fails when src and dest are the same
72 touch $t || framework_failure
73 ln -sf $t $t 2> /dev
/null
&& fail
=1
76 # Create a symlink with source file and no explicit directory
77 rm -rf $d || framework_failure
78 mkdir
$d || framework_failure
79 touch $d/$f || framework_failure
84 # Create a symlink with source file and destination symlink-to-directory.
85 rm -rf $d $f $ld || framework_failure
86 touch $f || framework_failure
87 mkdir
$d || framework_failure
89 ln -s ..
/$f $ld || fail
=1
90 test -f $d/$f || fail
=1
93 # Create a symlink with source file and destination symlink-to-directory.
94 # BUT use the new --no-dereference option.
95 rm -rf $d $f $ld || framework_failure
96 touch $f || framework_failure
97 mkdir
$d || framework_failure
100 ln --no-dereference -fs "$af" $ld || fail
=1
101 test -f $ld || fail
=1
104 # Try to create a symlink with backup where the destination file exists
105 # and the backup file name is a hard link to the destination file.
106 touch a b || framework_failure
107 ln b b~ || framework_failure
108 ln -f --b=simple a b || fail
=1
110 # ===================================================
111 # determine if link(2) follows symlinks on this system
112 touch a || framework_failure
113 ln -s a symlink || framework_failure
114 ln symlink hard-to-sym
> /dev
/null
2>&1 || framework_failure
115 ls=`ls -lG hard-to-sym`x
117 *'hard-to-symx') link_follows_symlink
=yes ;;
118 *'hard-to-sym -> ax') link_follows_symlink
=no
;;
119 *) framework_failure
;;
122 if test $link_follows_symlink = no
; then
123 # Create a hard link to a dangling symlink.
124 # This is not portable. At least sunos4.1.4 and OpenBSD 2.3 fail this test.
126 # ln: cannot create hard link `hard-to-dangle' to `no-such-dir': \
127 # No such file or directory
129 ln -s /no-such-dir || fail
=1
130 ln no-such-dir hard-to-dangle
> /dev
/null
2>&1 || fail
=1
132 rm -rf a symlink hard-to-sym hard-to-dangle
133 # ===================================================
135 # Make sure ln can make simple backups.
136 # This was fixed in 4.0.34. Broken in 4.0r.
137 for cmd
in ln cp mv ginstall
; do
139 touch a x || framework_failure
140 $cmd --backup=simple
--suffix=.orig x a || fail
=1
141 test -f a.orig || fail
=1
144 # ===================================================
145 # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
146 # I'm including it here, in case some day programs like valgrind detect that.
147 # Purify probably would have done so.
148 ln foo
'' 2> /dev
/null
150 # ===================================================
152 (exit $fail); exit $fail