Fixed test to work when objdir != srcdir (thanks to Art Haas).
[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 set -x
14
15 lddir="$tmpdir/ld"
16
17 chkfile="$scratchdir/rsync.chk"
18 outfile="$scratchdir/rsync.out"
19
20 # This is only called if rsync was run with -v or -vv (not -i alone).
21 # Higher levels of -v would require more filtering.
22 filter_outfile() {
23     sed -e '/^building file list /d' \
24         -e '/^created directory /d' \
25         -e '/^done$/d' \
26         -e '/ --whole-file$/d' \
27         -e '/^total: /d' \
28         -e '/^$/,$d' \
29         <"$outfile" >"$outfile.new"
30     mv "$outfile.new" "$outfile"
31 }
32
33 makepath "$fromdir/foo"
34 makepath "$fromdir/bar/baz"
35 cp -p "$srcdir/configure.in" "$fromdir/foo/config1"
36 cp -p "$srcdir/config.h.in" "$fromdir/foo/config2"
37 cp -p "$srcdir/rsync.h" "$fromdir/bar/baz/rsync"
38 chmod 600 "$fromdir"/foo/config? "$fromdir/bar/baz/rsync"
39 umask 0
40 ln -s ../bar/baz/rsync "$fromdir/foo/sym"
41 umask 022
42 ln "$fromdir/foo/config1" "$fromdir/foo/extra"
43
44 $RSYNC -iplr "$fromdir/" "$todir/" \
45     | tee "$outfile"
46 cat <<EOT >"$chkfile"
47 cd+++++++ bar/
48 cd+++++++ bar/baz/
49 >f+++++++ bar/baz/rsync
50 cd+++++++ foo/
51 >f+++++++ foo/config1
52 >f+++++++ foo/config2
53 >f+++++++ foo/extra
54 cL+++++++ foo/sym -> ../bar/baz/rsync
55 EOT
56 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
57
58 # Ensure there are no accidental directory-time problems.
59 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
60
61 cp -p "$srcdir/configure.in" "$fromdir/foo/config2"
62 chmod 601 "$fromdir/foo/config2"
63 $RSYNC -iplrH "$fromdir/" "$todir/" \
64     | tee "$outfile"
65 cat <<EOT >"$chkfile"
66 >f..T.... bar/baz/rsync
67 >f..T.... foo/config1
68 >f.sTp... foo/config2
69 hf..T.... foo/extra => foo/config1
70 EOT
71 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
72
73 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
74 sleep 1 # For directory mod below to ensure time difference
75 rm "$todir/foo/sym"
76 umask 0
77 ln -s ../bar/baz "$todir/foo/sym"
78 umask 022
79 cp -p "$srcdir/config.h.in" "$fromdir/foo/config2"
80 chmod 600 "$fromdir/foo/config2"
81 chmod 777 "$todir/bar/baz/rsync"
82
83 $RSYNC -iplrtc "$fromdir/" "$todir/" \
84     | tee "$outfile"
85 cat <<EOT >"$chkfile"
86 .f..tp... bar/baz/rsync
87 .d..t.... foo/
88 .f..t.... foo/config1
89 >fcstp... foo/config2
90 cL..T.... foo/sym -> ../bar/baz/rsync
91 EOT
92 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
93
94 cp -p "$srcdir/configure.in" "$fromdir/foo/config2"
95 chmod 600 "$fromdir/foo/config2"
96 # Lack of -t is for unchanged hard-link stress-test!
97 $RSYNC -vvplrH "$fromdir/" "$todir/" \
98     | tee "$outfile"
99 filter_outfile
100 cat <<EOT >"$chkfile"
101 bar/baz/rsync is uptodate
102 foo/config1 is uptodate
103 foo/config2
104 "foo/extra" is a hard link
105 foo/sym is uptodate
106 EOT
107 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
108
109 chmod 747 "$todir/bar/baz/rsync"
110 $RSYNC -a -f '-! */' "$fromdir/" "$todir"
111 $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
112     | tee "$outfile"
113 filter_outfile
114 cat <<EOT >"$chkfile"
115 .d        ./
116 .d        bar/
117 .d        bar/baz/
118 .f...p... bar/baz/rsync
119 .d        foo/
120 .f        foo/config1
121 >f..t.... foo/config2
122 hf        foo/extra
123 .L        foo/sym -> ../bar/baz/rsync
124 EOT
125 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
126
127 chmod 757 "$todir/foo/config1"
128 touch "$todir/foo/config2"
129 $RSYNC -vplrtH "$fromdir/" "$todir/" \
130     | tee "$outfile"
131 filter_outfile
132 cat <<EOT >"$chkfile"
133 foo/config2
134 EOT
135 diff $diffopt "$chkfile" "$outfile" || test_fail "test 6 failed"
136
137 chmod 757 "$todir/foo/config1"
138 touch "$todir/foo/config2"
139 $RSYNC -iplrtH "$fromdir/" "$todir/" \
140     | tee "$outfile"
141 cat <<EOT >"$chkfile"
142 .f...p... foo/config1
143 >f..t.... foo/config2
144 EOT
145 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
146
147 mv "$todir" "$lddir"
148 $RSYNC -ivvplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
149     | tee "$outfile"
150 filter_outfile
151 cat <<EOT >"$chkfile"
152 .d..t.... ./
153 cd+++++++ bar/
154 cd+++++++ bar/baz/
155 cf....... bar/baz/rsync
156 cd+++++++ foo/
157 cf....... foo/config1
158 cf....... foo/config2
159 hf+++++++ foo/extra => foo/config1
160 cL+++++++ foo/sym -> ../bar/baz/rsync
161 EOT
162 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
163
164 rm -rf "$todir"
165 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
166     | tee "$outfile"
167 cat <<EOT >"$chkfile"
168 .d..t.... ./
169 cd+++++++ bar/
170 cd+++++++ bar/baz/
171 cd+++++++ foo/
172 hf+++++++ foo/extra => foo/config1
173 cL+++++++ foo/sym -> ../bar/baz/rsync
174 EOT
175 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
176
177 # The script would have aborted on error, so getting here means we've won.
178 exit 0