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:
10: . "$suitedir/rsync.fns"
11:
12: chkfile="$scratchdir/rsync.chk"
13: outfile="$scratchdir/rsync.out"
14:
15: # Build some hardlinks
16:
17: case $0 in
18: *fake*)
19: $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests"
20: RSYNC="$RSYNC --fake-super"
21: TLS_ARGS="$TLS_ARGS --fake-super"
22: case "$HOST_OS" in
23: darwin*)
24: mknod() {
25: fn="$1"
26: case "$2" in
27: p) mode=10644 ;;
28: c) mode=20644 ;;
29: b) mode=60644 ;;
30: esac
31: maj="${3:-0}"
32: min="${4:-0}"
33: touch "$fn"
34: xattr -s 'rsync.%stat' "$mode $maj,$min 0:0" "$fn"
35: }
36: ;;
37: solaris*)
38: mknod() {
39: fn="$1"
40: case "$2" in
41: p) mode=10644 ;;
42: c) mode=20644 ;;
43: b) mode=60644 ;;
44: esac
45: maj="${3:-0}"
46: min="${4:-0}"
47: touch "$fn"
48: runat "$fn" "$SHELL_PATH" <<EOF
49: echo "$mode $maj,$min 0:0" > rsync.%stat
50: EOF
51: }
52: ;;
53: *)
54: mknod() {
55: fn="$1"
56: case "$2" in
57: p) mode=10644 ;;
58: c) mode=20644 ;;
59: b) mode=60644 ;;
60: esac
61: maj="${3:-0}"
62: min="${4:-0}"
63: touch "$fn"
64: setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn"
65: }
66: ;;
67: esac
68: ;;
69: *)
70: case `get_testuid` in
71: '') ;; # If "id" failed, try to continue...
72: 0) ;;
73: *) if [ -e "$FAKEROOT_PATH" ]; then
74: echo "Let's try re-running the script under fakeroot..."
75: exec "$FAKEROOT_PATH" "$SHELL_PATH" $RUNSHFLAGS "$0"
76: fi
77: test_skipped "Rsync needs root/fakeroot for device tests"
78: ;;
79: esac
80: ;;
81: esac
82:
83: # TODO: Need to test whether hardlinks are possible on this OS/filesystem
84:
85: mkdir "$fromdir"
86: mkdir "$todir"
87: mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node"
88: mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node"
89: mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node"
90: mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
91: mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
92: mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
93: ln "$fromdir/block3" "$fromdir/block3.5" || echo "Skipping hard-linked device test..."
94: mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
95: # Work around time rounding/truncating issue by touching both files.
96: touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2"
97:
98: $RSYNC -ai "$fromdir/block" "$todir/block2" \
99: | tee "$outfile"
100: cat <<EOT >"$chkfile"
101: cD$all_plus block
102: EOT
103: diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
104:
105: $RSYNC -ai "$fromdir/block2" "$todir/block" \
106: | tee "$outfile"
107: cat <<EOT >"$chkfile"
108: cD$all_plus block2
109: EOT
110: diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
111:
112: sleep 1
113:
114: $RSYNC -Di "$fromdir/block3" "$todir/block" \
115: | tee "$outfile"
116: cat <<EOT >"$chkfile"
117: cDc.T.$dots block3
118: EOT
119: diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
120:
121: $RSYNC -aiHvv "$fromdir/" "$todir/" \
122: | tee "$outfile"
123: filter_outfile
124: cat <<EOT >"$chkfile"
125: .d..t.$dots ./
126: cDc.t.$dots block
127: cDc...$dots block2
128: cD$all_plus block3
129: hD$all_plus block3.5 => block3
130: cD$all_plus char
131: cD$all_plus char2
132: cD$all_plus char3
133: cS$all_plus fifo
134: EOT
135: if test ! -r "$fromdir/block3.5"; then
136: grep -v block3.5 <"$chkfile" >"$chkfile.new"
137: mv "$chkfile.new" "$chkfile"
138: fi
139: diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
140:
141: echo "check how the directory listings compare with diff:"
142: echo ""
143: ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
144: ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
145: diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
146:
147: if test -r "$fromdir/block3.5"; then
148: set -x
149: $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
150: | tee "$outfile"
151: cat <<EOT >"$chkfile"
152: cd$allspace ./
153: hD$allspace block
154: hD$allspace block2
155: hD$allspace block3
156: hD$allspace block3.5
157: hD$allspace char
158: hD$allspace char2
159: hD$allspace char3
160: hS$allspace fifo
161: EOT
162: diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
163: fi
164:
165: # The script would have aborted on error, so getting here means we've won.
166: exit 0
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>