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 | 23 | fi |
9439c0cb WD |
24 | |
25 | # If we can't test the real device code, try to test --fake-super instead | |
26 | $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs root/fakeroot/--fake-super for device tests" | |
27 | RSYNC="$RSYNC --fake-super" | |
28 | export RSYNC_FAKE_SUPER=1 | |
29 | case "`xattr 2>&1`" in | |
30 | *--list:*) | |
31 | mknod() { | |
32 | fn="$1" | |
33 | case "$2" in | |
34 | p) mode=10644 ;; | |
35 | c) mode=20644 ;; | |
36 | b) mode=60644 ;; | |
37 | esac | |
38 | maj="${3:-0}" | |
39 | min="${4:-0}" | |
40 | touch "$fn" | |
41 | xattr -s 'rsync.%stat' "$mode $maj,$min 0:0" "$fn" | |
42 | } | |
43 | ;; | |
44 | *) | |
45 | mknod() { | |
46 | fn="$1" | |
47 | case "$2" in | |
48 | p) mode=10644 ;; | |
49 | c) mode=20644 ;; | |
50 | b) mode=60644 ;; | |
51 | esac | |
52 | maj="${3:-0}" | |
53 | min="${4:-0}" | |
54 | touch "$fn" | |
55 | setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn" | |
56 | } | |
57 | ;; | |
58 | esac | |
648859bd | 59 | ;; |
f5450e79 WD |
60 | esac |
61 | ||
355b8bcd MP |
62 | # TODO: Need to test whether hardlinks are possible on this OS/filesystem |
63 | ||
64 | mkdir "$fromdir" | |
9ac35913 | 65 | mkdir "$todir" |
9439c0cb WD |
66 | mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node" |
67 | mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node" | |
68 | mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node" | |
69 | mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node" | |
70 | mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node" | |
71 | mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node" | |
9ac35913 | 72 | ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..." |
9439c0cb | 73 | mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo" |
9ac35913 WD |
74 | touch -r "$fromdir/block" "$fromdir/block2" |
75 | ||
76 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ | |
77 | | tee "$outfile" | |
78 | cat <<EOT >"$chkfile" | |
1c3344a1 | 79 | cD+++++++++ block |
9ac35913 WD |
80 | EOT |
81 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
82 | ||
83 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ | |
84 | | tee "$outfile" | |
85 | cat <<EOT >"$chkfile" | |
1c3344a1 | 86 | cD+++++++++ block2 |
9ac35913 WD |
87 | EOT |
88 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
89 | ||
90 | sleep 1 | |
91 | ||
92 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ | |
93 | | tee "$outfile" | |
94 | cat <<EOT >"$chkfile" | |
1c3344a1 | 95 | cD..T...... block3 |
9ac35913 WD |
96 | EOT |
97 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
98 | ||
99 | $RSYNC -aiHvv "$fromdir/" "$todir/" \ | |
100 | | tee "$outfile" | |
101 | filter_outfile | |
102 | cat <<EOT >"$chkfile" | |
1c3344a1 WD |
103 | .d..t...... ./ |
104 | cD..t...... block | |
105 | cD block2 | |
106 | cD+++++++++ block3 | |
107 | hD+++++++++ block2.5 => block3 | |
108 | cD+++++++++ char | |
109 | cD+++++++++ char2 | |
110 | cD+++++++++ char3 | |
111 | cS+++++++++ fifo | |
9ac35913 | 112 | EOT |
9439c0cb WD |
113 | if test ! -r "$fromdir/block2.5"; then |
114 | sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new" | |
9ac35913 WD |
115 | mv "$chkfile.new" "$chkfile" |
116 | fi | |
117 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
355b8bcd | 118 | |
9ac35913 WD |
119 | echo "check how the directory listings compare with diff:" |
120 | echo "" | |
121 | ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from" | |
122 | ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to" | |
123 | diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" | |
355b8bcd | 124 | |
083f75ee WD |
125 | if test -b "$fromdir/block2.5"; then |
126 | set -x | |
127 | $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ | |
128 | | tee "$outfile" | |
129 | cat <<EOT >"$chkfile" | |
1c3344a1 WD |
130 | cd ./ |
131 | hD block | |
132 | hD block2 | |
133 | hD block2.5 | |
134 | hD block3 | |
135 | hD char | |
136 | hD char2 | |
137 | hD char3 | |
138 | hS fifo | |
083f75ee WD |
139 | EOT |
140 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
141 | fi | |
142 | ||
05118158 | 143 | # The script would have aborted on error, so getting here means we've won. |
355b8bcd | 144 | exit 0 |