2 # Test some of cp's options and how cp handles situations in
3 # which a naive implementation might overwrite the source file.
5 # Copyright (C) 1998-2000, 2002-2004, 2006-2010 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if test "$VERBOSE" = yes; then
27 # Unset CDPATH. Otherwise, output from the `cd dir' command
28 # can make this test fail.
29 (unset CDPATH
) >/dev
/null
2>&1 && unset CDPATH
31 VERSION_CONTROL
=numbered
; export VERSION_CONTROL
33 # Determine whether a hard link to a symlink points to the symlink
34 # itself or to its referent. For example, the link from FreeBSD6.1
35 # does dereference a symlink, but the one from Linux does not.
36 ln -s no-such dangling-slink
37 ln dangling-slink hard-link
> /dev
/null
2>&1 \
38 && hard_link_to_symlink_does_the_deref
=no \
39 || hard_link_to_symlink_does_the_deref
=yes
40 rm -f no-such dangling-slink hard-link
42 test $hard_link_to_symlink_does_the_deref = yes \
43 && remove_these_sed
='/^0 -[bf]*l .*sl1 ->/d' \
44 || remove_these_sed
='/^ELIDE NO TEST OUTPUT/d'
51 # FIXME: This should be bigger: like more than 8k
54 for args
in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do
55 for options
in '' -d -f -df --rem -b -bd -bf -bdf \
56 -l -dl -fl -dfl -bl -bdl -bfl -bdfl; do
58 # These tests are not portable.
59 # They all involve making a hard link to a symbolic link.
60 # In the past, we've skipped the tests that are not portable,
61 # by doing "continue" here and eliminating the corresponding
62 # expected output lines below. Don't do that anymore.
77 # cont'd Instead, skip them only on systems for which link does
78 # dereference a symlink. Detect and skip such tests here.
79 case $hard_link_to_symlink_does_the_deref:$args:$options in
92 case "$args" in *symlink
*) ln -s foo symlink
;; esac
93 case "$args" in *hardlink
*) ln foo hardlink
;; esac
94 case "$args" in *sl1
*) ln -s foo sl1
;; esac
95 case "$args" in *sl2
*) ln -s foo sl2
;; esac
98 # echo 1>&2 cp $options $args
99 cp $options $args 2>_err
102 # Normalize the program name and diagnostics in the error output,
103 # and put brackets around the output.
104 if test -s _err
; then
106 s/^[^:]*:\([^:]*\).*/cp:\1/
111 # Strip off all but the file names.
112 ls=`ls -gG --ignore=_err . \
115 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`
117 # Make sure the original is unchanged and that
118 # the destination is a copy.
137 cat <<\EOF |
sed "$remove_these_sed" > $expected
138 1 [cp: `foo' and `symlink
' are the same file] (foo symlink -> foo)
139 1 -d [cp: `foo' and
`symlink' are the same file] (foo symlink -> foo)
140 1 -f [cp: `foo
' and `symlink' are the same
file] (foo symlink
-> foo
)
141 1 -df [cp: `foo' and `symlink
' are the same file] (foo symlink -> foo)
142 0 --rem (foo symlink)
143 0 -b (foo symlink symlink.~1~ -> foo)
144 0 -bd (foo symlink symlink.~1~ -> foo)
145 0 -bf (foo symlink symlink.~1~ -> foo)
146 0 -bdf (foo symlink symlink.~1~ -> foo)
147 1 -l [cp: cannot create link `symlink'] (foo symlink
-> foo
)
148 0 -dl (foo symlink
-> foo
)
151 0 -bl (foo symlink symlink.~
1~
-> foo
)
152 0 -bdl (foo symlink symlink.~
1~
-> foo
)
153 0 -bfl (foo symlink symlink.~
1~
-> foo
)
154 0 -bdfl (foo symlink symlink.~
1~
-> foo
)
156 1 [cp: `symlink' and `foo
' are the same file] (foo symlink -> foo)
157 1 -d [cp: `symlink' and
`foo' are the same file] (foo symlink -> foo)
158 1 -f [cp: `symlink
' and `foo' are the same
file] (foo symlink
-> foo
)
159 1 -df [cp: `symlink' and `foo
' are the same file] (foo symlink -> foo)
160 1 --rem [cp: `symlink' and
`foo' are the same file] (foo symlink -> foo)
161 1 -b [cp: `symlink
' and `foo' are the same
file] (foo symlink
-> foo
)
162 0 -bd (foo
-> foo foo.~
1~ symlink
-> foo
) symlink-loop symlink-loop
163 1 -bf [cp: `symlink' and `foo
' are the same file] (foo symlink -> foo)
164 0 -bdf (foo -> foo foo.~1~ symlink -> foo) symlink-loop symlink-loop
165 0 -l (foo symlink -> foo)
166 0 -dl (foo symlink -> foo)
167 0 -fl (foo symlink -> foo)
168 0 -bl (foo symlink -> foo)
169 0 -bfl (foo symlink -> foo)
171 1 [cp: `foo' and
`foo' are the same file] (foo)
172 1 -d [cp: `foo
' and `foo' are the same
file] (foo
)
173 1 -f [cp: `foo' and `foo
' are the same file] (foo)
174 1 -df [cp: `foo' and
`foo' are the same file] (foo)
175 1 --rem [cp: `foo
' and `foo' are the same
file] (foo
)
176 1 -b [cp: `foo' and `foo
' are the same file] (foo)
177 1 -bd [cp: `foo' and
`foo' are the same file] (foo)
187 0 -bdfl (foo foo.~1~)
189 1 [cp: `sl1
' and `sl2' are the same
file] (foo sl1
-> foo sl2
-> foo
)
190 0 -d (foo sl1
-> foo sl2
-> foo
)
191 1 -f [cp: `sl1' and `sl2
' are the same file] (foo sl1 -> foo sl2 -> foo)
192 0 -df (foo sl1 -> foo sl2 -> foo)
193 0 --rem (foo sl1 -> foo sl2)
194 0 -b (foo sl1 -> foo sl2 sl2.~1~ -> foo)
195 0 -bd (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
196 0 -bf (foo sl1 -> foo sl2 sl2.~1~ -> foo)
197 0 -bdf (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo)
198 1 -l [cp: cannot create link `sl2'] (foo sl1
-> foo sl2
-> foo
)
199 0 -fl (foo sl1
-> foo sl2
-> foo
)
200 0 -bl (foo sl1
-> foo sl2
-> foo sl2.~
1~
-> foo
)
201 0 -bfl (foo sl1
-> foo sl2
-> foo sl2.~
1~
-> foo
)
203 1 [cp: `foo' and `hardlink
' are the same file] (foo hardlink)
204 1 -d [cp: `foo' and
`hardlink' are the same file] (foo hardlink)
205 1 -f [cp: `foo
' and `hardlink' are the same
file] (foo hardlink
)
206 1 -df [cp: `foo' and `hardlink
' are the same file] (foo hardlink)
207 0 --rem (foo hardlink)
208 0 -b (foo hardlink hardlink.~1~)
209 0 -bd (foo hardlink hardlink.~1~)
210 0 -bf (foo hardlink hardlink.~1~)
211 0 -bdf (foo hardlink hardlink.~1~)
215 0 -dfl (foo hardlink)
217 0 -bdl (foo hardlink)
218 0 -bfl (foo hardlink)
219 0 -bdfl (foo hardlink)
224 compare $expected $actual 1>&2 || fail=1