| 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$all_plus ./ |
| 57 | cd$all_plus bar/ |
| 58 | cd$all_plus bar/baz/ |
| 59 | >f$all_plus bar/baz/rsync |
| 60 | cd$all_plus foo/ |
| 61 | >f$all_plus foo/config1 |
| 62 | >f$all_plus foo/config2 |
| 63 | >f$all_plus foo/extra |
| 64 | cL$all_plus 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.$dots bar/baz/rsync |
| 77 | >f..T.$dots foo/config1 |
| 78 | >f.sTp$dots foo/config2 |
| 79 | hf..T.$dots 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$dots bar/baz/rsync |
| 97 | .d..t.$dots foo/ |
| 98 | .f..t.$dots foo/config1 |
| 99 | >fcstp$dots foo/config2 |
| 100 | cL.$T.$dots 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$allspace ./ |
| 126 | .d$allspace bar/ |
| 127 | .d$allspace bar/baz/ |
| 128 | .f...p$dots bar/baz/rsync |
| 129 | .d$allspace foo/ |
| 130 | .f$allspace foo/config1 |
| 131 | >f..t.$dots foo/config2 |
| 132 | hf$allspace foo/extra |
| 133 | .L$allspace 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$dots foo/config1 |
| 153 | >f..t.$dots 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.$dots" |
| 163 | L_sym_dots="cL$sym_dots" |
| 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="$allspace" |
| 170 | L_sym_dots=".L$allspace" |
| 171 | is_uptodate='is uptodate' |
| 172 | touch "$chkfile.extra" |
| 173 | ;; |
| 174 | esac |
| 175 | cat <<EOT >"$chkfile" |
| 176 | cd$allspace ./ |
| 177 | cd$allspace bar/ |
| 178 | cd$allspace bar/baz/ |
| 179 | cf$allspace bar/baz/rsync |
| 180 | cd$allspace foo/ |
| 181 | cf$allspace foo/config1 |
| 182 | cf$allspace foo/config2 |
| 183 | hf$allspace 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$allspace 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$allspace ./ |
| 219 | cd$allspace bar/ |
| 220 | cd$allspace bar/baz/ |
| 221 | hf$allspace bar/baz/rsync |
| 222 | cd$allspace foo/ |
| 223 | hf$allspace foo/config1 |
| 224 | hf$allspace foo/config2 |
| 225 | hf$allspace 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$allspace ./ |
| 267 | cd$allspace bar/ |
| 268 | cd$allspace bar/baz/ |
| 269 | .f$allspace bar/baz/rsync |
| 270 | cd$allspace foo/ |
| 271 | .f$allspace foo/config1 |
| 272 | .f$allspace foo/config2 |
| 273 | .f$allspace 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 |