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