2 # make sure cp and mv can handle many combinations of local and
3 # other-partition regular/symlink'd files.
5 # Copyright (C) 2000, 2003, 2004, 2006 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 2 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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 if test "$VERBOSE" = yes; then
30 trap 'status=$?; cd "$pwd" && exec 1>&2; rm -rf $tmp $other_partition_tmpdir && exit $status' 0
31 trap '(exit $?); exit' 1 2 13 15
35 . $srcdir/../other-fs-tmpdir
36 . $srcdir/../envvar-check
37 # Make sure the programs use C-locale formats/translations.
38 . $srcdir/../lang-default
40 # Unset CDPATH. Otherwise, output from the `cd dir' command
41 # can make this test fail.
42 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
44 if test -z "$other_partition_tmpdir"; then
49 mkdir $tmp || framework_failure=1
50 cd $tmp || framework_failure=1
52 if test $framework_failure = 1; then
53 echo 'failure in testing framework'
60 # local regular file w/symlink on another partition
63 # local symlink to regular file on another partition
67 # Exercise those four cases for each of
68 # cp and mv, with lots of combinations of options.
75 # FIXME: This should be bigger: like more than 8k
80 rem_reg=$other_partition_tmpdir/rem_reg
81 rem_sl=$other_partition_tmpdir/rem_sl
90 for options in '' --rem '--rem -d' '--rem -b' -b -bd -d; do
91 case "$options" in *d*|*--rem*) test $copy = mv && continue;; esac
93 rm -f $other_partition_tmpdir/* || fail=1
96 case "$args" in *loc_reg*) reg_abs="`pwd`/$loc_reg" ;; esac
97 case "$args" in *rem_reg*) reg_abs=$rem_reg ;; esac
98 case "$args" in *loc_sl*) slink=$loc_sl ;; esac
99 case "$args" in *rem_sl*) slink=$rem_sl ;; esac
101 echo $contents > "$reg_abs" || fail=1
102 ln -nsf "$reg_abs" $slink || fail=1
103 actual_args=`echo $args|sed 's,^,$,;s/ / $/'`
104 actual_args=`eval echo $actual_args`
108 # echo 1>&2 cp $options $args
109 $copy $options $actual_args 2>.err
111 echo $copy_status $copy $options $args
113 # Normalize the program name in the error output,
114 # remove any site-dependent part of other-partition file name,
115 # and put brackets around the output.
117 echo '[' | tr -d '\n'
118 sed 's/^[^:][^:]*\(..\):/\1:/;s,'$other_partition_tmpdir/,, .err
119 echo ']' | tr -d '\n'
121 # Strip off all but the file names.
122 # Remove any site-dependent part of each file name.
123 ls="`ls -gG --ignore=.err . \
126 -e s,$other_partition_tmpdir/,, \
128 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`"
129 ls2="`cd $other_partition_tmpdir && ls -gG --ignore=.err . \
132 -e s,$other_partition_tmpdir/,, \
134 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`"
137 # If the command failed, then it must not have changed the files.
138 if test $copy_status != 0; then
139 for f in $actual_args; do
141 { echo "$copy FAILED but removed $f"; continue; }
144 *) echo "$copy FAILED but modified $f";;
149 if test $copy = cp; then
150 # Make sure the original is unchanged and that
151 # the destination is a copy.
152 for f in $actual_args; do
154 if test $copy_status != 0; then
159 *) echo $copy FAILED;;
178 cat <<\EOF > $expected
179 1 cp loc_reg rem_sl [cp: `loc_reg' and `rem_sl' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
180 0 cp --rem loc_reg rem_sl (loc_reg) (rem_sl)
181 0 cp --rem -d loc_reg rem_sl (loc_reg) (rem_sl)
182 0 cp --rem -b loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
183 0 cp -b loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
184 0 cp -bd loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
185 1 cp -d loc_reg rem_sl [cp: `loc_reg' and `rem_sl' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
187 1 cp rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
188 1 cp --rem rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
189 1 cp --rem -d rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
190 1 cp --rem -b rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
191 1 cp -b rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
192 0 cp -bd rem_sl loc_reg (loc_reg -> dir/loc_reg loc_reg~) (rem_sl -> dir/loc_reg) symlink-loop symlink-loop
193 1 cp -d rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
195 1 cp loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
196 1 cp --rem loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
197 1 cp --rem -d loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
198 1 cp --rem -b loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
199 1 cp -b loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
200 0 cp -bd loc_sl rem_reg (loc_sl -> rem_reg) (rem_reg -> rem_reg rem_reg~) symlink-loop symlink-loop
201 1 cp -d loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
203 1 cp rem_reg loc_sl [cp: `rem_reg' and `loc_sl' are the same file ](loc_sl -> rem_reg) (rem_reg)
204 0 cp --rem rem_reg loc_sl (loc_sl) (rem_reg)
205 0 cp --rem -d rem_reg loc_sl (loc_sl) (rem_reg)
206 0 cp --rem -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
207 0 cp -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
208 0 cp -bd rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
209 1 cp -d rem_reg loc_sl [cp: `rem_reg' and `loc_sl' are the same file ](loc_sl -> rem_reg) (rem_reg)
211 0 mv loc_reg rem_sl () (rem_sl)
212 0 mv -b loc_reg rem_sl () (rem_sl rem_sl~ -> dir/loc_reg)
214 1 mv rem_sl loc_reg [mv: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
215 0 mv -b rem_sl loc_reg (loc_reg -> dir/loc_reg loc_reg~) ()
217 1 mv loc_sl rem_reg [mv: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
218 0 mv -b loc_sl rem_reg () (rem_reg -> rem_reg rem_reg~)
220 0 mv rem_reg loc_sl (loc_sl) ()
221 0 mv -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) ()
225 # Some folks may don't have diff.
226 cmp $expected $actual \
227 || { diff -c $expected $actual 1>&2; fail=1; }
229 (exit $fail); exit $fail