Fixed the hard-link check again, adding a comment as to
[rsync/rsync.git] / testsuite / itemize.test
1 #! /bin/sh
2
3 # Copyright (C) 2005 by Wayne Davison <wayned@samba.org>
4
5 # This program is distributable under the terms of the GNU GPL (see
6 # COPYING).
7
8 # Test the output of various copy commands to ensure itemized output
9 # and double-verbose output is correct.
10
11 . "$suitedir/rsync.fns"
12
13 to2dir="$tmpdir/to2"
14
15 chkfile="$scratchdir/rsync.chk"
16 outfile="$scratchdir/rsync.out"
17
18 makepath "$fromdir/foo"
19 makepath "$fromdir/bar/baz"
20 cp -p "$srcdir/configure.in" "$fromdir/foo/config1"
21 cp -p "$srcdir/config.h.in" "$fromdir/foo/config2"
22 cp -p "$srcdir/rsync.h" "$fromdir/bar/baz/rsync"
23 chmod 600 "$fromdir"/foo/config? "$fromdir/bar/baz/rsync"
24 umask 0
25 ln -s ../bar/baz/rsync "$fromdir/foo/sym"
26 umask 022
27 ln "$fromdir/foo/config1" "$fromdir/foo/extra"
28
29 # Check if the OS can hard-link symlinks or not.
30 # (Note: the link we check MUST NOT point to a valid file!)
31 ln -s no-such-dir "$to2dir"
32 if ln "$to2dir" "$to2dir.test" 2>/dev/null; then
33     L=hL
34 else
35     L=cL
36 fi
37 rm -f "$to2dir" "$to2dir.test"
38
39 # Check if rsync can preserve time on symlinks
40 case "$RSYNC" in
41 *protocol=2*)
42     T=.T
43     ;;
44 *)
45     if $RSYNC --version | grep ", symtimes" >/dev/null; then
46         T=.t
47     else
48         T=.T
49     fi
50     ;;
51 esac
52
53 $RSYNC -iplr "$fromdir/" "$todir/" \
54     | tee "$outfile"
55 cat <<EOT >"$chkfile"
56 cd+++++++++ ./
57 cd+++++++++ bar/
58 cd+++++++++ bar/baz/
59 >f+++++++++ bar/baz/rsync
60 cd+++++++++ foo/
61 >f+++++++++ foo/config1
62 >f+++++++++ foo/config2
63 >f+++++++++ foo/extra
64 cL+++++++++ foo/sym -> ../bar/baz/rsync
65 EOT
66 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
67
68 # Ensure there are no accidental directory-time problems.
69 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
70
71 cp -p "$srcdir/configure.in" "$fromdir/foo/config2"
72 chmod 601 "$fromdir/foo/config2"
73 $RSYNC -iplrH "$fromdir/" "$todir/" \
74     | tee "$outfile"
75 cat <<EOT >"$chkfile"
76 >f..T...... bar/baz/rsync
77 >f..T...... foo/config1
78 >f.sTp..... foo/config2
79 hf..T...... foo/extra => foo/config1
80 EOT
81 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
82
83 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
84 sleep 1 # For directory mod below to ensure time difference
85 rm "$todir/foo/sym"
86 umask 0
87 ln -s ../bar/baz "$todir/foo/sym"
88 umask 022
89 cp -p "$srcdir/config.h.in" "$fromdir/foo/config2"
90 chmod 600 "$fromdir/foo/config2"
91 chmod 777 "$todir/bar/baz/rsync"
92
93 $RSYNC -iplrtc "$fromdir/" "$todir/" \
94     | tee "$outfile"
95 cat <<EOT >"$chkfile"
96 .f..tp..... bar/baz/rsync
97 .d..t...... foo/
98 .f..t...... foo/config1
99 >fcstp..... foo/config2
100 cL.$T...... foo/sym -> ../bar/baz/rsync
101 EOT
102 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
103
104 cp -p "$srcdir/configure.in" "$fromdir/foo/config2"
105 chmod 600 "$fromdir/foo/config2"
106 # Lack of -t is for unchanged hard-link stress-test!
107 $RSYNC -vvplrH "$fromdir/" "$todir/" \
108     | tee "$outfile"
109 filter_outfile
110 cat <<EOT >"$chkfile"
111 bar/baz/rsync is uptodate
112 foo/config1 is uptodate
113 foo/config2
114 foo/extra is uptodate
115 foo/sym is uptodate
116 EOT
117 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
118
119 chmod 747 "$todir/bar/baz/rsync"
120 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
121 $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
122     | tee "$outfile"
123 filter_outfile
124 cat <<EOT >"$chkfile"
125 .d          ./
126 .d          bar/
127 .d          bar/baz/
128 .f...p..... bar/baz/rsync
129 .d          foo/
130 .f          foo/config1
131 >f..t...... foo/config2
132 hf          foo/extra
133 .L          foo/sym -> ../bar/baz/rsync
134 EOT
135 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
136
137 chmod 757 "$todir/foo/config1"
138 touch "$todir/foo/config2"
139 $RSYNC -vplrtH "$fromdir/" "$todir/" \
140     | tee "$outfile"
141 filter_outfile
142 cat <<EOT >"$chkfile"
143 foo/config2
144 EOT
145 diff $diffopt "$chkfile" "$outfile" || test_fail "test 6 failed"
146
147 chmod 757 "$todir/foo/config1"
148 touch "$todir/foo/config2"
149 $RSYNC -iplrtH "$fromdir/" "$todir/" \
150     | tee "$outfile"
151 cat <<EOT >"$chkfile"
152 .f...p..... foo/config1
153 >f..t...... foo/config2
154 EOT
155 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
156
157 $RSYNC -ivvplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
158     | tee "$outfile"
159 filter_outfile
160 case `tail -1 "$outfile"` in
161 cL..t*)
162     sym_dots='..t......'
163     L_sym_dots='cL..t......'
164     is_uptodate='-> ../bar/baz/rsync'
165     echo "cL$sym_dots foo/sym $is_uptodate" >"$chkfile.extra"
166     L=cL
167     ;;
168 *)
169     sym_dots='         '
170     L_sym_dots='.L         '
171     is_uptodate='is uptodate'
172     touch "$chkfile.extra"
173     ;;
174 esac
175 cat <<EOT >"$chkfile"
176 cd          ./
177 cd          bar/
178 cd          bar/baz/
179 cf          bar/baz/rsync
180 cd          foo/
181 cf          foo/config1
182 cf          foo/config2
183 hf          foo/extra => foo/config1
184 cL$sym_dots foo/sym -> ../bar/baz/rsync
185 EOT
186 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
187
188 rm -rf "$to2dir"
189 $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
190     | tee "$outfile"
191 cat - "$chkfile.extra" <<EOT >"$chkfile"
192 hf          foo/extra => foo/config1
193 EOT
194 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
195
196 rm -rf "$to2dir"
197 $RSYNC -vvplrtH --copy-dest="$todir" "$fromdir/" "$to2dir/" \
198     | tee "$outfile"
199 filter_outfile
200 cat <<EOT >"$chkfile"
201 ./ is uptodate
202 bar/ is uptodate
203 bar/baz/ is uptodate
204 bar/baz/rsync is uptodate
205 foo/ is uptodate
206 foo/config1 is uptodate
207 foo/config2 is uptodate
208 foo/extra => foo/config1
209 foo/sym $is_uptodate
210 EOT
211 diff $diffopt "$chkfile" "$outfile" || test_fail "test 10 failed"
212
213 rm -rf "$to2dir"
214 $RSYNC -ivvplrtH --link-dest="$todir" "$fromdir/" "$to2dir/" \
215     | tee "$outfile"
216 filter_outfile
217 cat <<EOT >"$chkfile"
218 cd          ./
219 cd          bar/
220 cd          bar/baz/
221 hf          bar/baz/rsync
222 cd          foo/
223 hf          foo/config1
224 hf          foo/config2
225 hf          foo/extra => foo/config1
226 $L$sym_dots foo/sym -> ../bar/baz/rsync
227 EOT
228 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
229
230 rm -rf "$to2dir"
231 $RSYNC -iplrtH --dry-run --link-dest=../to "$fromdir/" "$to2dir/" \
232     | tee "$outfile"
233 cat - "$chkfile.extra" <<EOT >"$chkfile"
234 EOT
235 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
236
237 rm -rf "$to2dir"
238 $RSYNC -iplrtH --link-dest=../to "$fromdir/" "$to2dir/" \
239     | tee "$outfile"
240 cat - "$chkfile.extra" <<EOT >"$chkfile"
241 EOT
242 diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed"
243
244 rm -rf "$to2dir"
245 $RSYNC -vvplrtH --link-dest="$todir" "$fromdir/" "$to2dir/" \
246     | tee "$outfile"
247 filter_outfile
248 cat <<EOT >"$chkfile"
249 ./ is uptodate
250 bar/ is uptodate
251 bar/baz/ is uptodate
252 bar/baz/rsync is uptodate
253 foo/ is uptodate
254 foo/config1 is uptodate
255 foo/config2 is uptodate
256 foo/extra is uptodate
257 foo/sym $is_uptodate
258 EOT
259 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
260
261 rm -rf "$to2dir"
262 $RSYNC -ivvplrtH --compare-dest="$todir" "$fromdir/" "$to2dir/" \
263     | tee "$outfile"
264 filter_outfile
265 cat <<EOT >"$chkfile"
266 cd          ./
267 cd          bar/
268 cd          bar/baz/
269 .f          bar/baz/rsync
270 cd          foo/
271 .f          foo/config1
272 .f          foo/config2
273 .f          foo/extra
274 $L_sym_dots foo/sym -> ../bar/baz/rsync
275 EOT
276 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
277
278 rm -rf "$to2dir"
279 $RSYNC -iplrtH --compare-dest="$todir" "$fromdir/" "$to2dir/" \
280     | tee "$outfile"
281 cat - "$chkfile.extra" <<EOT >"$chkfile"
282 EOT
283 diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed"
284
285 rm -rf "$to2dir"
286 $RSYNC -vvplrtH --compare-dest="$todir" "$fromdir/" "$to2dir/" \
287     | tee "$outfile"
288 filter_outfile
289 cat <<EOT >"$chkfile"
290 ./ is uptodate
291 bar/ is uptodate
292 bar/baz/ is uptodate
293 bar/baz/rsync is uptodate
294 foo/ is uptodate
295 foo/config1 is uptodate
296 foo/config2 is uptodate
297 foo/extra is uptodate
298 foo/sym $is_uptodate
299 EOT
300 diff $diffopt "$chkfile" "$outfile" || test_fail "test 17 failed"
301
302 # The script would have aborted on error, so getting here means we've won.
303 exit 0