Adding the --fake-super option.
[rsync/rsync.git] / testsuite / devices.test
... / ...
CommitLineData
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
12chkfile="$scratchdir/rsync.chk"
13outfile="$scratchdir/rsync.out"
14
15# Build some hardlinks
16
17case `id -u` in
18'') ;; # If "id" failed, try to continue...
190) ;;
20*) if [ -f /usr/bin/fakeroot ]; then
21 echo "Let's try re-running the script under fakeroot..."
22 exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0"
23 fi
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
59 ;;
60esac
61
62# TODO: Need to test whether hardlinks are possible on this OS/filesystem
63
64mkdir "$fromdir"
65mkdir "$todir"
66mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node"
67mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node"
68mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node"
69mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
70mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
71mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
72ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
73mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
74touch -r "$fromdir/block" "$fromdir/block2"
75
76$RSYNC -ai "$fromdir/block" "$todir/block2" \
77 | tee "$outfile"
78cat <<EOT >"$chkfile"
79cD+++++++++ block
80EOT
81diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
82
83$RSYNC -ai "$fromdir/block2" "$todir/block" \
84 | tee "$outfile"
85cat <<EOT >"$chkfile"
86cD+++++++++ block2
87EOT
88diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
89
90sleep 1
91
92$RSYNC -Di "$fromdir/block3" "$todir/block" \
93 | tee "$outfile"
94cat <<EOT >"$chkfile"
95cD..T...... block3
96EOT
97diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
98
99$RSYNC -aiHvv "$fromdir/" "$todir/" \
100 | tee "$outfile"
101filter_outfile
102cat <<EOT >"$chkfile"
103.d..t...... ./
104cD..t...... block
105cD block2
106cD+++++++++ block3
107hD+++++++++ block2.5 => block3
108cD+++++++++ char
109cD+++++++++ char2
110cD+++++++++ char3
111cS+++++++++ fifo
112EOT
113if test ! -r "$fromdir/block2.5"; then
114 sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new"
115 mv "$chkfile.new" "$chkfile"
116fi
117diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
118
119echo "check how the directory listings compare with diff:"
120echo ""
121( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
122( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
123diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
124
125if test -b "$fromdir/block2.5"; then
126 set -x
127 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
128 | tee "$outfile"
129 cat <<EOT >"$chkfile"
130cd ./
131hD block
132hD block2
133hD block2.5
134hD block3
135hD char
136hD char2
137hD char3
138hS fifo
139EOT
140 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
141fi
142
143# The script would have aborted on error, so getting here means we've won.
144exit 0