Annotation of embedaddon/rsync/testsuite/devices.test, revision 1.1.1.1

1.1       misho       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: 
                     12: chkfile="$scratchdir/rsync.chk"
                     13: outfile="$scratchdir/rsync.out"
                     14: 
                     15: # Build some hardlinks
                     16: 
                     17: case $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:     ;;
                     65: esac
                     66: 
                     67: # TODO: Need to test whether hardlinks are possible on this OS/filesystem
                     68: 
                     69: mkdir "$fromdir"
                     70: mkdir "$todir"
                     71: mknod "$fromdir/char" c 41 67  || test_skipped "Can't create char device node"
                     72: mknod "$fromdir/char2" c 42 68  || test_skipped "Can't create char device node"
                     73: mknod "$fromdir/char3" c 42 69  || test_skipped "Can't create char device node"
                     74: mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
                     75: mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
                     76: mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
                     77: ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
                     78: mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
                     79: # Work around time rounding/truncating issue by touching both files.
                     80: touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2"
                     81: 
                     82: $RSYNC -ai "$fromdir/block" "$todir/block2" \
                     83:     | tee "$outfile"
                     84: cat <<EOT >"$chkfile"
                     85: cD$all_plus block
                     86: EOT
                     87: diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
                     88: 
                     89: $RSYNC -ai "$fromdir/block2" "$todir/block" \
                     90:     | tee "$outfile"
                     91: cat <<EOT >"$chkfile"
                     92: cD$all_plus block2
                     93: EOT
                     94: diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
                     95: 
                     96: sleep 1
                     97: 
                     98: $RSYNC -Di "$fromdir/block3" "$todir/block" \
                     99:     | tee "$outfile"
                    100: cat <<EOT >"$chkfile"
                    101: cDc.T.$dots block3
                    102: EOT
                    103: diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
                    104: 
                    105: $RSYNC -aiHvv "$fromdir/" "$todir/" \
                    106:     | tee "$outfile"
                    107: filter_outfile
                    108: cat <<EOT >"$chkfile"
                    109: .d..t.$dots ./
                    110: cDc.t.$dots block
                    111: cDc...$dots block2
                    112: cD$all_plus block3
                    113: hD$all_plus block2.5 => block3
                    114: cD$all_plus char
                    115: cD$all_plus char2
                    116: cD$all_plus char3
                    117: cS$all_plus fifo
                    118: EOT
                    119: if test ! -r "$fromdir/block2.5"; then
                    120:     grep -v block2.5 <"$chkfile" >"$chkfile.new"
                    121:     mv "$chkfile.new" "$chkfile"
                    122: fi
                    123: diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
                    124: 
                    125: echo "check how the directory listings compare with diff:"
                    126: echo ""
                    127: ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
                    128: ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
                    129: diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
                    130: 
                    131: if test -r "$fromdir/block2.5"; then
                    132:     set -x
                    133:     $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
                    134:        | tee "$outfile"
                    135:     cat <<EOT >"$chkfile"
                    136: cd$allspace ./
                    137: hD$allspace block
                    138: hD$allspace block2
                    139: hD$allspace block2.5
                    140: hD$allspace block3
                    141: hD$allspace char
                    142: hD$allspace char2
                    143: hD$allspace char3
                    144: hS$allspace fifo
                    145: EOT
                    146:     diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
                    147: fi
                    148: 
                    149: # The script would have aborted on error, so getting here means we've won.
                    150: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>