global: convert indentation-TABs to spaces
[coreutils.git] / tests / mv / part-symlink
blob71788b9056866a70ac543543b16914271dc921dc
1 #!/bin/sh
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-2009 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
21 set -x
22 mv --version
23 cp --version
26 . $srcdir/test-lib.sh
27 cleanup_() { rm -rf "$other_partition_tmpdir"; }
28 . "$abs_srcdir/other-fs-tmpdir"
30 pwd_tmp=`pwd`
32 # Unset CDPATH. Otherwise, output from the `cd dir' command
33 # can make this test fail.
34 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
36 fail=0
38 # Four cases:
39 # local regular file w/symlink on another partition
40 # (loc_reg, rem_sl)
41 # (rem_sl, loc_reg)
42 # local symlink to regular file on another partition
43 # (loc_sl, rem_reg)
44 # (rem_reg, loc_sl)
46 # Exercise those four cases for each of
47 # cp and mv, with lots of combinations of options.
49 actual=actual-$$
50 expected=expected-$$
52 exec 1> $actual
54 # FIXME: This should be bigger: like more than 8k
55 contents=XYZ
57 loc_reg=loc_reg
58 loc_sl=loc_sl
59 rem_reg=$other_partition_tmpdir/rem_reg
60 rem_sl=$other_partition_tmpdir/rem_sl
62 for copy in cp mv; do
63 for args in \
64 'loc_reg rem_sl' \
65 'rem_sl loc_reg' \
66 'loc_sl rem_reg' \
67 'rem_reg loc_sl' \
68 ; do
69 for options in '' --rem '--rem -d' '--rem -b' -b -bd -d; do
70 case "$options" in *d*|*--rem*) test $copy = mv && continue;; esac
71 rm -rf dir || fail=1
72 rm -f $other_partition_tmpdir/* || fail=1
73 mkdir dir || fail=1
74 cd dir || fail=1
75 case "$args" in *loc_reg*) reg_abs="`pwd`/$loc_reg" ;; esac
76 case "$args" in *rem_reg*) reg_abs=$rem_reg ;; esac
77 case "$args" in *loc_sl*) slink=$loc_sl ;; esac
78 case "$args" in *rem_sl*) slink=$rem_sl ;; esac
80 echo $contents > "$reg_abs" || fail=1
81 ln -nsf "$reg_abs" $slink || fail=1
82 actual_args=`echo $args|sed 's,^,$,;s/ / $/'`
83 actual_args=`eval echo $actual_args`
87 # echo 1>&2 cp $options $args
88 $copy $options $actual_args 2>.err
89 copy_status=$?
90 echo $copy_status $copy $options $args
92 # Normalize the program name in the error output,
93 # remove any site-dependent part of other-partition file name,
94 # and put brackets around the output.
95 test -s .err && {
96 echo '[' | tr -d '\n'
97 sed 's/^[^:][^:]*\(..\):/\1:/;s,'$other_partition_tmpdir/,, .err
98 echo ']' | tr -d '\n'
100 # Strip off all but the file names.
101 # Remove any site-dependent part of each file name.
102 ls=`ls -gG --ignore=.err . \
103 | sed \
104 -e '/^total /d' \
105 -e s,$other_partition_tmpdir/,, \
106 -e "s,$pwd_tmp/,," \
107 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`
108 ls2=`cd $other_partition_tmpdir && ls -gG --ignore=.err . \
109 | sed \
110 -e '/^total /d' \
111 -e s,$other_partition_tmpdir/,, \
112 -e "s,$pwd_tmp/,," \
113 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`
114 echo "($ls) ($ls2)"
116 # If the command failed, then it must not have changed the files.
117 if test $copy_status != 0; then
118 for f in $actual_args; do
119 test -f $f ||
120 { echo "$copy FAILED but removed $f"; continue; }
121 case "`cat $f`" in
122 "$contents") ;;
123 *) echo "$copy FAILED but modified $f";;
124 esac
125 done
128 if test $copy = cp; then
129 # Make sure the original is unchanged and that
130 # the destination is a copy.
131 for f in $actual_args; do
132 if test -f $f; then
133 if test $copy_status != 0; then
134 test
136 case "`cat $f`" in
137 "$contents") ;;
138 *) echo $copy FAILED;;
139 esac
140 else
141 echo symlink-loop
143 done
145 ) | tr '\n' ' '
146 echo
147 ) | sed 's/ *$//'
148 cd ..
149 done
150 echo
151 done
152 done
154 test $fail = 1 &&
155 { (exit 1); exit; }
157 cat <<\EOF > $expected
158 1 cp loc_reg rem_sl [cp: `loc_reg' and `rem_sl' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
159 0 cp --rem loc_reg rem_sl (loc_reg) (rem_sl)
160 0 cp --rem -d loc_reg rem_sl (loc_reg) (rem_sl)
161 0 cp --rem -b loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
162 0 cp -b loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
163 0 cp -bd loc_reg rem_sl (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
164 1 cp -d loc_reg rem_sl [cp: `loc_reg' and `rem_sl' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
166 1 cp rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
167 1 cp --rem rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
168 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)
169 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)
170 1 cp -b rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
171 0 cp -bd rem_sl loc_reg (loc_reg -> dir/loc_reg loc_reg~) (rem_sl -> dir/loc_reg) symlink-loop symlink-loop
172 1 cp -d rem_sl loc_reg [cp: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
174 1 cp loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
175 1 cp --rem loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
176 1 cp --rem -d loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
177 1 cp --rem -b loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
178 1 cp -b loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
179 0 cp -bd loc_sl rem_reg (loc_sl -> rem_reg) (rem_reg -> rem_reg rem_reg~) symlink-loop symlink-loop
180 1 cp -d loc_sl rem_reg [cp: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
182 1 cp rem_reg loc_sl [cp: `rem_reg' and `loc_sl' are the same file ](loc_sl -> rem_reg) (rem_reg)
183 0 cp --rem rem_reg loc_sl (loc_sl) (rem_reg)
184 0 cp --rem -d rem_reg loc_sl (loc_sl) (rem_reg)
185 0 cp --rem -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
186 0 cp -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
187 0 cp -bd rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) (rem_reg)
188 1 cp -d rem_reg loc_sl [cp: `rem_reg' and `loc_sl' are the same file ](loc_sl -> rem_reg) (rem_reg)
190 0 mv loc_reg rem_sl () (rem_sl)
191 0 mv -b loc_reg rem_sl () (rem_sl rem_sl~ -> dir/loc_reg)
193 1 mv rem_sl loc_reg [mv: `rem_sl' and `loc_reg' are the same file ](loc_reg) (rem_sl -> dir/loc_reg)
194 0 mv -b rem_sl loc_reg (loc_reg -> dir/loc_reg loc_reg~) ()
196 1 mv loc_sl rem_reg [mv: `loc_sl' and `rem_reg' are the same file ](loc_sl -> rem_reg) (rem_reg)
197 0 mv -b loc_sl rem_reg () (rem_reg -> rem_reg rem_reg~)
199 0 mv rem_reg loc_sl (loc_sl) ()
200 0 mv -b rem_reg loc_sl (loc_sl loc_sl~ -> rem_reg) ()
204 # Redirect to stderr, since stdout is already taken.
205 compare $expected $actual 1>&2 || fail=1
207 Exit $fail