Avoid -u option to id since solaris doesn't support it.
[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 $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 "`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
52 ;;
53*)
54 case `get_testuid` in
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 ;;
65esac
66
67# TODO: Need to test whether hardlinks are possible on this OS/filesystem
68
69mkdir "$fromdir"
70mkdir "$todir"
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"
77ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
78mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
79# Work around time rounding/truncating issue by touching both files.
80touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2"
81
82$RSYNC -ai "$fromdir/block" "$todir/block2" \
83 | tee "$outfile"
84cat <<EOT >"$chkfile"
85cD$all_plus block
86EOT
87diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
88
89$RSYNC -ai "$fromdir/block2" "$todir/block" \
90 | tee "$outfile"
91cat <<EOT >"$chkfile"
92cD$all_plus block2
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"
101cDc.T.$dots block3
102EOT
103diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
104
105$RSYNC -aiHvv "$fromdir/" "$todir/" \
106 | tee "$outfile"
107filter_outfile
108cat <<EOT >"$chkfile"
109.d..t.$dots ./
110cDc.t.$dots block
111cDc...$dots block2
112cD$all_plus block2.5
113hD$all_plus block3 => block2.5
114cD$all_plus char
115cD$all_plus char2
116cD$all_plus char3
117cS$all_plus fifo
118EOT
119if test ! -r "$fromdir/block2.5"; then
120 sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new"
121 mv "$chkfile.new" "$chkfile"
122fi
123diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
124
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"
130
131if test -b "$fromdir/block2.5"; then
132 set -x
133 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
134 | tee "$outfile"
135 cat <<EOT >"$chkfile"
136cd$allspace ./
137hD$allspace block
138hD$allspace block2
139hD$allspace block2.5
140hD$allspace block3
141hD$allspace char
142hD$allspace char2
143hD$allspace char3
144hS$allspace fifo
145EOT
146 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
147fi
148
149# The script would have aborted on error, so getting here means we've won.
150exit 0