2 # Miscellaneous tests for "ln".
4 # Copyright (C) 1998, 1999, 2000, 2004, 2006 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 2 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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 if test "$VERBOSE" = yes; then
28 trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
29 trap '(exit $?); exit' 1 2 13 15
32 mkdir $tmp || framework_failure=1
33 cd $tmp || framework_failure=1
37 ld=tln-symlink-to-subdir
41 # Create a simple symlink with both source and destination files
42 # in current directory.
43 touch $f || framework_failure=1
44 rm -f $t || framework_failure=1
49 # Create a symlink with source file and explicit destination directory/file.
50 touch $f || framework_failure=1
51 rm -rf $d || framework_failure=1
52 mkdir $d || framework_failure=1
53 ln -s ../$f $d/$t || fail=1
54 test -f $d/$t || fail=1
57 # Create a symlink with source file and destination directory.
58 touch $f || framework_failure=1
59 rm -rf $d || framework_failure=1
60 mkdir $d || framework_failure=1
61 ln -s ../$f $d || fail=1
62 test -f $d/$f || fail=1
65 # See whether a trailing slash is followed too far.
66 touch $f || framework_failure=1
67 rm -rf $d || framework_failure=1
68 mkdir $d $d/$f || framework_failure=1
69 ln $f $d/ 2> /dev/null && fail=1
70 ln -s $f $d/ 2> /dev/null && fail=1
73 # Make sure we get a failure with existing dest without -f option
74 touch $t || framework_failure=1
75 # FIXME: don't ignore the error message but rather test
76 # it to make sure it's the right one.
77 ln -s $t $t 2> /dev/null && fail=1
80 # Make sure -sf fails when src and dest are the same
81 touch $t || framework_failure=1
82 ln -sf $t $t 2> /dev/null && fail=1
85 # Create a symlink with source file and no explicit directory
86 rm -rf $d || framework_failure=1
87 mkdir $d || framework_failure=1
88 touch $d/$f || framework_failure=1
93 # Create a symlink with source file and destination symlink-to-directory.
94 rm -rf $d $f $ld || framework_failure=1
95 touch $f || framework_failure=1
96 mkdir $d || framework_failure=1
98 ln -s ../$f $ld || fail=1
99 test -f $d/$f || fail=1
102 # Create a symlink with source file and destination symlink-to-directory.
103 # BUT use the new --no-dereference option.
104 rm -rf $d $f $ld || framework_failure=1
105 touch $f || framework_failure=1
106 mkdir $d || framework_failure=1
109 ln --no-dereference -fs "$af" $ld || fail=1
110 test -f $ld || fail=1
113 # Try to create a symlink with backup where the destination file exists
114 # and the backup file name is a hard link to the destination file.
115 touch a b || framework_failure=1
116 ln b b~ || framework_failure=1
117 ln -f --b=simple a b || fail=1
119 # ===================================================
120 # determine if link(2) follows symlinks on this system
121 touch a || framework_failure=1
122 ln -s a symlink || framework_failure=1
123 ln symlink hard-to-sym > /dev/null 2>&1 || framework_failure=1
124 ls=`ls -lG hard-to-sym`x
126 *'hard-to-symx') link_follows_symlink=yes ;;
127 *'hard-to-sym -> ax') link_follows_symlink=no ;;
128 *) framework_failure=1 ;;
131 if test $link_follows_symlink = no; then
132 # Create a hard link to a dangling symlink.
133 # This is not portable. At least sunos4.1.4 and OpenBSD 2.3 fail this test.
135 # ln: cannot create hard link `hard-to-dangle' to `no-such-dir': \
136 # No such file or directory
138 ln -s /no-such-dir || fail=1
139 ln no-such-dir hard-to-dangle > /dev/null 2>&1 || fail=1
141 rm -rf a symlink hard-to-sym hard-to-dangle
142 # ===================================================
144 # Make sure ln can make simple backups.
145 # This was fixed in 4.0.34. Broken in 4.0r.
146 for cmd in ln cp mv ginstall; do
148 touch a x || framework_failure=1
149 $cmd --backup=simple --suffix=.orig x a || fail=1
150 test -f a.orig || fail=1
153 # ===================================================
154 # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
155 # I'm including it here, in case some day programs like valgrind detect that.
156 # Purify probably would have done so.
157 ln foo '' 2> /dev/null
159 # ===================================================
161 if test $framework_failure = 1; then
162 echo 'failure in testing framework' 1>&2