Fix issue with devices-fake test.
[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
9557eaba
WD
17case $0 in
18*fake*)
19 $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests"
9439c0cb 20 RSYNC="$RSYNC --fake-super"
5b385336 21 TLS_ARGS="$TLS_ARGS --fake-super"
9439c0cb
WD
22 case "`xattr 2>&1`" in
23 *--list:*)
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 *)
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 setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn"
49 }
50 ;;
51 esac
648859bd 52 ;;
9557eaba 53*)
8e7f3107 54 case `get_testuid` in
9557eaba
WD
55 '') ;; # If "id" failed, try to continue...
56 0) ;;
57 *) if [ -f /usr/bin/fakeroot ]; then
58 echo "Let's try re-running the script under fakeroot..."
59 exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0"
60 fi
61 test_skipped "Rsync needs root/fakeroot for device tests"
62 ;;
63 esac
64 ;;
f5450e79
WD
65esac
66
355b8bcd
MP
67# TODO: Need to test whether hardlinks are possible on this OS/filesystem
68
69mkdir "$fromdir"
9ac35913 70mkdir "$todir"
9439c0cb
WD
71mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node"
72mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node"
73mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node"
74mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
75mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
76mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
b2e446d0 77ln "$fromdir/block3" "$fromdir/block3.5" || echo "Skipping hard-linked device test..."
9439c0cb 78mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
844810d6
WD
79# Work around time rounding/truncating issue by touching both files.
80touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2"
9ac35913 81
fc3ca110 82$RSYNC -ai "$fromdir/block" "$todir/block2" \
9ac35913
WD
83 | tee "$outfile"
84cat <<EOT >"$chkfile"
fc29efc3 85cD$all_plus block
9ac35913
WD
86EOT
87diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
88
fc3ca110 89$RSYNC -ai "$fromdir/block2" "$todir/block" \
9ac35913
WD
90 | tee "$outfile"
91cat <<EOT >"$chkfile"
fc29efc3 92cD$all_plus block2
9ac35913
WD
93EOT
94diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
95
96sleep 1
97
98$RSYNC -Di "$fromdir/block3" "$todir/block" \
99 | tee "$outfile"
100cat <<EOT >"$chkfile"
1ed9018e 101cDc.T.$dots block3
9ac35913
WD
102EOT
103diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
104
105$RSYNC -aiHvv "$fromdir/" "$todir/" \
106 | tee "$outfile"
107filter_outfile
108cat <<EOT >"$chkfile"
fc29efc3 109.d..t.$dots ./
1ed9018e
WD
110cDc.t.$dots block
111cDc...$dots block2
b2e446d0
WD
112cD$all_plus block3
113hD$all_plus block3.5 => block3
fc29efc3
WD
114cD$all_plus char
115cD$all_plus char2
116cD$all_plus char3
117cS$all_plus fifo
9ac35913 118EOT
c82711b3 119if test ! -r "$fromdir/block3.5"; then
b2e446d0 120 grep -v block3.5 <"$chkfile" >"$chkfile.new"
9ac35913
WD
121 mv "$chkfile.new" "$chkfile"
122fi
123diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
355b8bcd 124
9ac35913
WD
125echo "check how the directory listings compare with diff:"
126echo ""
127( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
128( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
129diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
355b8bcd 130
c82711b3 131if test -r "$fromdir/block3.5"; then
083f75ee
WD
132 set -x
133 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
134 | tee "$outfile"
135 cat <<EOT >"$chkfile"
fc29efc3
WD
136cd$allspace ./
137hD$allspace block
138hD$allspace block2
fc29efc3 139hD$allspace block3
b2e446d0 140hD$allspace block3.5
fc29efc3
WD
141hD$allspace char
142hD$allspace char2
143hD$allspace char3
144hS$allspace fifo
083f75ee 145EOT
b2e446d0 146 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
083f75ee
WD
147fi
148
05118158 149# The script would have aborted on error, so getting here means we've won.
355b8bcd 150exit 0