Commit | Line | Data |
---|---|---|
355b8bcd MP |
1 | #! /bin/sh |
2 | ||
3 | # Copyright (C) 2002 by Martin Pool <mbp@samba.org> | |
4 | ||
5 | # This program is distributable under the terms of the GNU GPL (see | |
6 | # COPYING). | |
7 | ||
8 | # Test rsync handling of devices. This can only run if you're root. | |
9 | ||
b0e9bafc | 10 | . "$suitedir/rsync.fns" |
355b8bcd | 11 | |
9ac35913 WD |
12 | chkfile="$scratchdir/rsync.chk" |
13 | outfile="$scratchdir/rsync.out" | |
14 | ||
15 | # This is only called if rsync was run with -v or -vv (not -i alone). | |
16 | # Higher levels of -v would require more filtering. | |
17 | filter_outfile() { | |
18 | sed -e '/^building file list /d' \ | |
19 | -e '/^created directory /d' \ | |
20 | -e '/^done$/d' \ | |
21 | -e '/ --whole-file$/d' \ | |
22 | -e '/^total: /d' \ | |
23 | -e '/^$/,$d' \ | |
24 | <"$outfile" >"$outfile.new" | |
25 | mv "$outfile.new" "$outfile" | |
26 | } | |
27 | ||
355b8bcd MP |
28 | # Build some hardlinks |
29 | ||
f5450e79 WD |
30 | case `id -u` in |
31 | '') ;; # If "id" failed, try to continue... | |
648859bd WD |
32 | 0) ;; |
33 | *) if [ -f /usr/bin/fakeroot ]; then | |
bb21ecac | 34 | echo "Let's try re-running the script under fakeroot..." |
8f5b554f | 35 | exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0" |
648859bd WD |
36 | fi |
37 | test_skipped "Rsync won't copy devices unless we're root" | |
38 | ;; | |
f5450e79 WD |
39 | esac |
40 | ||
355b8bcd MP |
41 | # TODO: Need to test whether hardlinks are possible on this OS/filesystem |
42 | ||
43 | mkdir "$fromdir" | |
9ac35913 | 44 | mkdir "$todir" |
f09dc86a WD |
45 | mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node unless root" |
46 | mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node unless root" | |
47 | mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node unless root" | |
7a176e87 | 48 | mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node unless root" |
ab264c9e S |
49 | mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node unless root" |
50 | mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node unless root" | |
9ac35913 | 51 | ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..." |
fdb6716c | 52 | mkfifo "$fromdir/fifo" || test_skipped "Can't run mkfifo" |
9ac35913 WD |
53 | touch -r "$fromdir/block" "$fromdir/block2" |
54 | ||
55 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ | |
56 | | tee "$outfile" | |
57 | cat <<EOT >"$chkfile" | |
58 | cD++++++ block | |
59 | EOT | |
60 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
61 | ||
62 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ | |
63 | | tee "$outfile" | |
64 | cat <<EOT >"$chkfile" | |
65 | cD++++++ block2 | |
66 | EOT | |
67 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
68 | ||
69 | sleep 1 | |
70 | ||
71 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ | |
72 | | tee "$outfile" | |
73 | cat <<EOT >"$chkfile" | |
74 | cD..T... block3 | |
75 | EOT | |
76 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
77 | ||
78 | $RSYNC -aiHvv "$fromdir/" "$todir/" \ | |
79 | | tee "$outfile" | |
80 | filter_outfile | |
81 | cat <<EOT >"$chkfile" | |
82 | .d..t... ./ | |
83 | cD..t... block | |
84 | cD...... block2 | |
85 | cD++++++ block3 | |
86 | hD++++++ block2.5 => block3 | |
87 | cD++++++ char | |
88 | cD++++++ char2 | |
89 | cD++++++ char3 | |
e5f6a04d | 90 | cS++++++ fifo |
9ac35913 WD |
91 | EOT |
92 | if test ! -b "$fromdir/block2.5"; then | |
93 | sed -e '/block2\.5/d' \ | |
94 | <"$chkfile" >"$chkfile.new" | |
95 | mv "$chkfile.new" "$chkfile" | |
96 | fi | |
97 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
355b8bcd | 98 | |
9ac35913 WD |
99 | echo "check how the directory listings compare with diff:" |
100 | echo "" | |
101 | ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from" | |
102 | ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to" | |
103 | diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" | |
355b8bcd | 104 | |
05118158 | 105 | # The script would have aborted on error, so getting here means we've won. |
355b8bcd | 106 | exit 0 |