Adding the --fake-super option.
[rsync/rsync.git] / testsuite / devices.test
CommitLineData
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
12chkfile="$scratchdir/rsync.chk"
13outfile="$scratchdir/rsync.out"
14
355b8bcd
MP
15# Build some hardlinks
16
f5450e79
WD
17case `id -u` in
18'') ;; # If "id" failed, try to continue...
648859bd
WD
190) ;;
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
60esac
61
355b8bcd
MP
62# TODO: Need to test whether hardlinks are possible on this OS/filesystem
63
64mkdir "$fromdir"
9ac35913 65mkdir "$todir"
9439c0cb
WD
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"
9ac35913 72ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
9439c0cb 73mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
9ac35913
WD
74touch -r "$fromdir/block" "$fromdir/block2"
75
76$RSYNC -ai "$fromdir/block" "$todir/block2" \
77 | tee "$outfile"
78cat <<EOT >"$chkfile"
1c3344a1 79cD+++++++++ block
9ac35913
WD
80EOT
81diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
82
83$RSYNC -ai "$fromdir/block2" "$todir/block" \
84 | tee "$outfile"
85cat <<EOT >"$chkfile"
1c3344a1 86cD+++++++++ block2
9ac35913
WD
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"
1c3344a1 95cD..T...... block3
9ac35913
WD
96EOT
97diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
98
99$RSYNC -aiHvv "$fromdir/" "$todir/" \
100 | tee "$outfile"
101filter_outfile
102cat <<EOT >"$chkfile"
1c3344a1
WD
103.d..t...... ./
104cD..t...... block
105cD block2
106cD+++++++++ block3
107hD+++++++++ block2.5 => block3
108cD+++++++++ char
109cD+++++++++ char2
110cD+++++++++ char3
111cS+++++++++ fifo
9ac35913 112EOT
9439c0cb
WD
113if test ! -r "$fromdir/block2.5"; then
114 sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new"
9ac35913
WD
115 mv "$chkfile.new" "$chkfile"
116fi
117diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
355b8bcd 118
9ac35913
WD
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"
355b8bcd 124
083f75ee
WD
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"
1c3344a1
WD
130cd ./
131hD block
132hD block2
133hD block2.5
134hD block3
135hD char
136hD char2
137hD char3
138hS fifo
083f75ee
WD
139EOT
140 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
141fi
142
05118158 143# The script would have aborted on error, so getting here means we've won.
355b8bcd 144exit 0