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 | ||
355b8bcd MP |
15 | # Build some hardlinks |
16 | ||
f5450e79 WD |
17 | case `id -u` in |
18 | '') ;; # If "id" failed, try to continue... | |
648859bd WD |
19 | 0) ;; |
20 | *) if [ -f /usr/bin/fakeroot ]; then | |
bb21ecac | 21 | echo "Let's try re-running the script under fakeroot..." |
8f5b554f | 22 | exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0" |
648859bd WD |
23 | fi |
24 | test_skipped "Rsync won't copy devices unless we're root" | |
25 | ;; | |
f5450e79 WD |
26 | esac |
27 | ||
355b8bcd MP |
28 | # TODO: Need to test whether hardlinks are possible on this OS/filesystem |
29 | ||
30 | mkdir "$fromdir" | |
9ac35913 | 31 | mkdir "$todir" |
f09dc86a WD |
32 | mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node unless root" |
33 | mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node unless root" | |
34 | mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node unless root" | |
7a176e87 | 35 | mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node unless root" |
ab264c9e S |
36 | mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node unless root" |
37 | mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node unless root" | |
9ac35913 | 38 | ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..." |
fdb6716c | 39 | mkfifo "$fromdir/fifo" || test_skipped "Can't run mkfifo" |
9ac35913 WD |
40 | touch -r "$fromdir/block" "$fromdir/block2" |
41 | ||
42 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ | |
43 | | tee "$outfile" | |
44 | cat <<EOT >"$chkfile" | |
503f1634 | 45 | cD+++++++ block |
9ac35913 WD |
46 | EOT |
47 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
48 | ||
49 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ | |
50 | | tee "$outfile" | |
51 | cat <<EOT >"$chkfile" | |
503f1634 | 52 | cD+++++++ block2 |
9ac35913 WD |
53 | EOT |
54 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
55 | ||
56 | sleep 1 | |
57 | ||
58 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ | |
59 | | tee "$outfile" | |
60 | cat <<EOT >"$chkfile" | |
503f1634 | 61 | cD..T.... block3 |
9ac35913 WD |
62 | EOT |
63 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
64 | ||
65 | $RSYNC -aiHvv "$fromdir/" "$todir/" \ | |
66 | | tee "$outfile" | |
67 | filter_outfile | |
68 | cat <<EOT >"$chkfile" | |
503f1634 WD |
69 | .d..t.... ./ |
70 | cD..t.... block | |
083f75ee | 71 | cD block2 |
503f1634 WD |
72 | cD+++++++ block3 |
73 | hD+++++++ block2.5 => block3 | |
74 | cD+++++++ char | |
75 | cD+++++++ char2 | |
76 | cD+++++++ char3 | |
77 | cS+++++++ fifo | |
9ac35913 WD |
78 | EOT |
79 | if test ! -b "$fromdir/block2.5"; then | |
80 | sed -e '/block2\.5/d' \ | |
81 | <"$chkfile" >"$chkfile.new" | |
82 | mv "$chkfile.new" "$chkfile" | |
83 | fi | |
84 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
355b8bcd | 85 | |
9ac35913 WD |
86 | echo "check how the directory listings compare with diff:" |
87 | echo "" | |
88 | ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from" | |
89 | ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to" | |
90 | diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" | |
355b8bcd | 91 | |
083f75ee WD |
92 | if test -b "$fromdir/block2.5"; then |
93 | set -x | |
94 | $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ | |
95 | | tee "$outfile" | |
96 | cat <<EOT >"$chkfile" | |
97 | cd ./ | |
98 | hD block | |
99 | hD block2 | |
100 | hD block2.5 | |
101 | hD block3 | |
102 | hD char | |
103 | hD char2 | |
104 | hD char3 | |
105 | hS fifo | |
106 | EOT | |
107 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
108 | fi | |
109 | ||
05118158 | 110 | # The script would have aborted on error, so getting here means we've won. |
355b8bcd | 111 | exit 0 |