tests: change `...' to '...' on lines not matching /[=\$]/
[coreutils.git] / tests / mv / part-symlink
blob82a82c6742f34fc3f61f31cca8309d2df8d55e7d
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-2012 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 . "${srcdir=.}/init.sh"; path_prepend_ ../src
21 print_ver_ cp mv
23 cleanup_() { rm -rf "$other_partition_tmpdir"; }
24 . "$abs_srcdir/other-fs-tmpdir"
26 # On NFS on Linux 2.6.9 at least we get:
27 # mv: preserving permissions for 'rem_sl': Operation not supported
28 require_local_dir_
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
37 # Four cases:
38 # local regular file w/symlink on another partition
39 # (loc_reg, rem_sl)
40 # (rem_sl, loc_reg)
41 # local symlink to regular file on another partition
42 # (loc_sl, rem_reg)
43 # (rem_reg, loc_sl)
45 # Exercise those four cases for each of
46 # cp and mv, with lots of combinations of options.
48 exec 1> actual
50 # FIXME: This should be bigger: like more than 8k
51 contents=XYZ
53 loc_reg=loc_reg
54 loc_sl=loc_sl
55 rem_reg=$other_partition_tmpdir/rem_reg
56 rem_sl=$other_partition_tmpdir/rem_sl
58 for copy in cp mv; do
59 for args in \
60 'loc_reg rem_sl' \
61 'rem_sl loc_reg' \
62 'loc_sl rem_reg' \
63 'rem_reg loc_sl' \
64 ; do
65 for options in '' --rem '--rem -d' '--rem -b' -b -bd -d; do
66 case "$options" in *d*|*--rem*) test $copy = mv && continue;; esac
67 rm -rf dir || fail=1
68 rm -f "$other_partition_tmpdir"/* || fail=1
69 mkdir dir || fail=1
70 cd dir || fail=1
71 case "$args" in *loc_reg*) reg_abs="`pwd`/$loc_reg" ;; esac
72 case "$args" in *rem_reg*) reg_abs=$rem_reg ;; esac
73 case "$args" in *loc_sl*) slink=$loc_sl ;; esac
74 case "$args" in *rem_sl*) slink=$rem_sl ;; esac
76 echo $contents > "$reg_abs" || fail=1
77 ln -nsf "$reg_abs" $slink || fail=1
78 actual_args=`echo $args|sed 's,^,$,;s/ / $/'`
79 actual_args=`eval echo $actual_args`
83 # echo 1>&2 cp $options $args
84 $copy $options $actual_args 2>.err
85 copy_status=$?
86 echo $copy_status $copy $options $args
88 # Normalize the program name in the error output,
89 # remove any site-dependent part of other-partition file name,
90 # and put brackets around the output.
91 test -s .err && {
92 echo ' [' | tr -d '\n'
93 sed 's/^[^:][^:]*\(..\):/\1:/;s,'"$other_partition_tmpdir/,," .err |
94 tr -d '\n'
95 echo ']'
97 # Strip off all but the file names.
98 # Remove any site-dependent part of each file name.
99 ls=`ls -gG --ignore=.err . \
100 | sed \
101 -e '/^total /d' \
102 -e "s,$other_partition_tmpdir/,," \
103 -e "s,$pwd_tmp/,," \
104 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`
105 ls2=`cd "$other_partition_tmpdir" && ls -gG --ignore=.err . \
106 | sed \
107 -e '/^total /d' \
108 -e "s,$other_partition_tmpdir/,," \
109 -e "s,$pwd_tmp/,," \
110 -e 's/^[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//'`
111 echo " ("$ls") ("$ls2")"
113 # If the command failed, then it must not have changed the files.
114 if test $copy_status != 0; then
115 for f in $actual_args; do
116 test -f $f ||
117 { echo " $copy FAILED but removed $f"; continue; }
118 case "`cat $f`" in
119 "$contents") ;;
120 *) echo " $copy FAILED but modified $f";;
121 esac
122 done
125 if test $copy = cp; then
126 # Make sure the original is unchanged and that
127 # the destination is a copy.
128 for f in $actual_args; do
129 if test -f $f; then
130 if test $copy_status != 0; then
131 test
133 case "`cat $f`" in
134 "$contents") ;;
135 *) echo " $copy FAILED";;
136 esac
137 else
138 echo " symlink-loop"
140 done
143 ) | sed 's/ *$//'
144 cd ..
145 done
146 echo
147 done
148 done
150 test $fail = 1 &&
151 { (exit 1); exit; }
153 cat <<\EOF > expected
154 1 cp loc_reg rem_sl
155 [cp: 'loc_reg' and 'rem_sl' are the same file]
156 (loc_reg) (rem_sl -> dir/loc_reg)
157 0 cp --rem loc_reg rem_sl
158 (loc_reg) (rem_sl)
159 0 cp --rem -d loc_reg rem_sl
160 (loc_reg) (rem_sl)
161 0 cp --rem -b loc_reg rem_sl
162 (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
163 0 cp -b loc_reg rem_sl
164 (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
165 0 cp -bd loc_reg rem_sl
166 (loc_reg) (rem_sl rem_sl~ -> dir/loc_reg)
167 1 cp -d loc_reg rem_sl
168 [cp: 'loc_reg' and 'rem_sl' are the same file]
169 (loc_reg) (rem_sl -> dir/loc_reg)
171 1 cp rem_sl loc_reg
172 [cp: 'rem_sl' and 'loc_reg' are the same file]
173 (loc_reg) (rem_sl -> dir/loc_reg)
174 1 cp --rem rem_sl loc_reg
175 [cp: 'rem_sl' and 'loc_reg' are the same file]
176 (loc_reg) (rem_sl -> dir/loc_reg)
177 1 cp --rem -d rem_sl loc_reg
178 [cp: 'rem_sl' and 'loc_reg' are the same file]
179 (loc_reg) (rem_sl -> dir/loc_reg)
180 1 cp --rem -b rem_sl loc_reg
181 [cp: 'rem_sl' and 'loc_reg' are the same file]
182 (loc_reg) (rem_sl -> dir/loc_reg)
183 1 cp -b rem_sl loc_reg
184 [cp: 'rem_sl' and 'loc_reg' are the same file]
185 (loc_reg) (rem_sl -> dir/loc_reg)
186 0 cp -bd rem_sl loc_reg
187 (loc_reg -> dir/loc_reg loc_reg~) (rem_sl -> dir/loc_reg)
188 symlink-loop
189 symlink-loop
190 1 cp -d rem_sl loc_reg
191 [cp: 'rem_sl' and 'loc_reg' are the same file]
192 (loc_reg) (rem_sl -> dir/loc_reg)
194 1 cp loc_sl rem_reg
195 [cp: 'loc_sl' and 'rem_reg' are the same file]
196 (loc_sl -> rem_reg) (rem_reg)
197 1 cp --rem loc_sl rem_reg
198 [cp: 'loc_sl' and 'rem_reg' are the same file]
199 (loc_sl -> rem_reg) (rem_reg)
200 1 cp --rem -d loc_sl rem_reg
201 [cp: 'loc_sl' and 'rem_reg' are the same file]
202 (loc_sl -> rem_reg) (rem_reg)
203 1 cp --rem -b loc_sl rem_reg
204 [cp: 'loc_sl' and 'rem_reg' are the same file]
205 (loc_sl -> rem_reg) (rem_reg)
206 1 cp -b loc_sl rem_reg
207 [cp: 'loc_sl' and 'rem_reg' are the same file]
208 (loc_sl -> rem_reg) (rem_reg)
209 0 cp -bd loc_sl rem_reg
210 (loc_sl -> rem_reg) (rem_reg -> rem_reg rem_reg~)
211 symlink-loop
212 symlink-loop
213 1 cp -d loc_sl rem_reg
214 [cp: 'loc_sl' and 'rem_reg' are the same file]
215 (loc_sl -> rem_reg) (rem_reg)
217 1 cp rem_reg loc_sl
218 [cp: 'rem_reg' and 'loc_sl' are the same file]
219 (loc_sl -> rem_reg) (rem_reg)
220 0 cp --rem rem_reg loc_sl
221 (loc_sl) (rem_reg)
222 0 cp --rem -d rem_reg loc_sl
223 (loc_sl) (rem_reg)
224 0 cp --rem -b rem_reg loc_sl
225 (loc_sl loc_sl~ -> rem_reg) (rem_reg)
226 0 cp -b rem_reg loc_sl
227 (loc_sl loc_sl~ -> rem_reg) (rem_reg)
228 0 cp -bd rem_reg loc_sl
229 (loc_sl loc_sl~ -> rem_reg) (rem_reg)
230 1 cp -d rem_reg loc_sl
231 [cp: 'rem_reg' and 'loc_sl' are the same file]
232 (loc_sl -> rem_reg) (rem_reg)
234 0 mv loc_reg rem_sl
235 () (rem_sl)
236 0 mv -b loc_reg rem_sl
237 () (rem_sl rem_sl~ -> dir/loc_reg)
239 1 mv rem_sl loc_reg
240 [mv: 'rem_sl' and 'loc_reg' are the same file]
241 (loc_reg) (rem_sl -> dir/loc_reg)
242 0 mv -b rem_sl loc_reg
243 (loc_reg -> dir/loc_reg loc_reg~) ()
245 1 mv loc_sl rem_reg
246 [mv: 'loc_sl' and 'rem_reg' are the same file]
247 (loc_sl -> rem_reg) (rem_reg)
248 0 mv -b loc_sl rem_reg
249 () (rem_reg -> rem_reg rem_reg~)
251 0 mv rem_reg loc_sl
252 (loc_sl) ()
253 0 mv -b rem_reg loc_sl
254 (loc_sl loc_sl~ -> rem_reg) ()
258 # Redirect to stderr, since stdout is already taken.
259 compare expected actual 1>&2 || fail=1
261 Exit $fail