2 # Miscellaneous tests for "ln".
4 # Copyright (C) 1998-2000, 2004, 2006-2009 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
28 ld=tln-symlink-to-subdir
31 # Create a simple symlink with both source and destination files
32 # in current directory.
33 touch $f || framework_failure
34 rm -f $t || framework_failure
39 # Create a symlink with source file and explicit destination directory/file.
40 touch $f || framework_failure
41 rm -rf $d || framework_failure
42 mkdir $d || framework_failure
43 ln -s ../$f $d/$t || fail=1
44 test -f $d/$t || fail=1
47 # Create a symlink with source file and destination directory.
48 touch $f || framework_failure
49 rm -rf $d || framework_failure
50 mkdir $d || framework_failure
51 ln -s ../$f $d || fail=1
52 test -f $d/$f || fail=1
55 # See whether a trailing slash is followed too far.
56 touch $f || framework_failure
57 rm -rf $d || framework_failure
58 mkdir $d $d/$f || framework_failure
59 ln $f $d/ 2> /dev/null && fail=1
60 ln -s $f $d/ 2> /dev/null && fail=1
63 # Make sure we get a failure with existing dest without -f option
64 touch $t || framework_failure
65 # FIXME: don't ignore the error message but rather test
66 # it to make sure it's the right one.
67 ln -s $t $t 2> /dev/null && fail=1
70 # Make sure -sf fails when src and dest are the same
71 touch $t || framework_failure
72 ln -sf $t $t 2> /dev/null && fail=1
75 # Create a symlink with source file and no explicit directory
76 rm -rf $d || framework_failure
77 mkdir $d || framework_failure
78 touch $d/$f || framework_failure
83 # Create a symlink with source file and destination symlink-to-directory.
84 rm -rf $d $f $ld || framework_failure
85 touch $f || framework_failure
86 mkdir $d || framework_failure
88 ln -s ../$f $ld || fail=1
89 test -f $d/$f || fail=1
92 # Create a symlink with source file and destination symlink-to-directory.
93 # BUT use the new --no-dereference option.
94 rm -rf $d $f $ld || framework_failure
95 touch $f || framework_failure
96 mkdir $d || framework_failure
99 ln --no-dereference -fs "$af" $ld || fail=1
100 test -f $ld || fail=1
103 # Try to create a symlink with backup where the destination file exists
104 # and the backup file name is a hard link to the destination file.
105 touch a b || framework_failure
106 ln b b~ || framework_failure
107 ln -f --b=simple a b || fail=1
109 # ===================================================
111 # Make sure ln can make simple backups.
112 # This was fixed in 4.0.34. Broken in 4.0r.
113 for cmd in ln cp mv ginstall; do
115 touch a x || framework_failure
116 $cmd --backup=simple --suffix=.orig x a || fail=1
117 test -f a.orig || fail=1
120 # ===================================================
121 # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
122 # I'm including it here, in case some day programs like valgrind detect that.
123 # Purify probably would have done so.
124 ln foo '' 2> /dev/null
126 # ===================================================