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 test_skipped "Rsync won't copy devices unless we're root" 25 ;; 26esac 27 28# TODO: Need to test whether hardlinks are possible on this OS/filesystem 29 30mkdir "$fromdir" 31mkdir "$todir" 32mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node unless root" 33mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node unless root" 34mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node unless root" 35mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node unless root" 36mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node unless root" 37mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node unless root" 38ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..." 39mkfifo "$fromdir/fifo" || test_skipped "Can't run mkfifo" 40touch -r "$fromdir/block" "$fromdir/block2" 41 42$RSYNC -ai "$fromdir/block" "$todir/block2" \ 43 | tee "$outfile" 44cat <<EOT >"$chkfile" 45cD+++++++ block 46EOT 47diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" 48 49$RSYNC -ai "$fromdir/block2" "$todir/block" \ 50 | tee "$outfile" 51cat <<EOT >"$chkfile" 52cD+++++++ block2 53EOT 54diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" 55 56sleep 1 57 58$RSYNC -Di "$fromdir/block3" "$todir/block" \ 59 | tee "$outfile" 60cat <<EOT >"$chkfile" 61cD..T.... block3 62EOT 63diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" 64 65$RSYNC -aiHvv "$fromdir/" "$todir/" \ 66 | tee "$outfile" 67filter_outfile 68cat <<EOT >"$chkfile" 69.d..t.... ./ 70cD..t.... block 71cD....... block2 72cD+++++++ block3 73hD+++++++ block2.5 => block3 74cD+++++++ char 75cD+++++++ char2 76cD+++++++ char3 77cS+++++++ fifo 78EOT 79if test ! -b "$fromdir/block2.5"; then 80 sed -e '/block2\.5/d' \ 81 <"$chkfile" >"$chkfile.new" 82 mv "$chkfile.new" "$chkfile" 83fi 84diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" 85 86echo "check how the directory listings compare with diff:" 87echo "" 88( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from" 89( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to" 90diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" 91 92# The script would have aborted on error, so getting here means we've won. 93exit 0 94