Annotation of embedaddon/rsync/testsuite/xattrs.test, revision 1.1

1.1     ! misho       1: #! /bin/sh
        !             2: 
        !             3: # This program is distributable under the terms of the GNU GPL (see
        !             4: # COPYING).
        !             5: 
        !             6: # Test that rsync handles basic xattr preservation.
        !             7: 
        !             8: . $srcdir/testsuite/rsync.fns
        !             9: lnkdir="$tmpdir/lnk"
        !            10: 
        !            11: $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync is configured without xattr support"
        !            12: 
        !            13: case "`xattr 2>&1`" in
        !            14: *--list:*)
        !            15:     xset() {
        !            16:        xnam="$1"
        !            17:        xval="$2"
        !            18:        shift 2
        !            19:        xattr -s "$xnam" "$xval" "${@}"
        !            20:     }
        !            21:     xls() {
        !            22:        xattr -l "${@}" | sed "s/^[ $tab_ch]*//"
        !            23:     }
        !            24:     RSYNC_PREFIX='rsync'
        !            25:     RUSR='rsync.nonuser'
        !            26:     ;;
        !            27: *)
        !            28:     xset() {
        !            29:        xnam="$1"
        !            30:        xval="$2"
        !            31:        shift 2
        !            32:        setfattr -n "$xnam" -v "$xval" "${@}"
        !            33:     }
        !            34:     xls() {
        !            35:        getfattr -d "${@}"
        !            36:     }
        !            37:     RSYNC_PREFIX='user.rsync'
        !            38:     RUSR='user.rsync'
        !            39:     ;;
        !            40: esac
        !            41: 
        !            42: makepath "$lnkdir" "$fromdir/foo/bar"
        !            43: echo now >"$fromdir/file0"
        !            44: echo something >"$fromdir/file1"
        !            45: echo else >"$fromdir/file2"
        !            46: echo deep >"$fromdir/foo/file3"
        !            47: echo normal >"$fromdir/file4"
        !            48: echo deeper >"$fromdir/foo/bar/file5"
        !            49: 
        !            50: makepath "$chkdir/foo"
        !            51: echo wow >"$chkdir/file1"
        !            52: cp_touch "$fromdir/foo/file3" "$chkdir/foo"
        !            53: 
        !            54: dirs='foo foo/bar'
        !            55: files='file0 file1 file2 foo/file3 file4 foo/bar/file5'
        !            56: 
        !            57: uid_gid=`"$TOOLDIR/tls" "$fromdir/foo" | sed 's/^.* \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/\1:\2/'`
        !            58: 
        !            59: cd "$fromdir"
        !            60: 
        !            61: xset user.foo foo file0 2>/dev/null || test_skipped "Unable to set an xattr"
        !            62: xset user.bar bar file0
        !            63: 
        !            64: xset user.short 'this is short' file1
        !            65: xset user.long 'this is a long attribute that will be truncated in the initial data send' file1
        !            66: xset user.good 'this is good' file1
        !            67: xset user.nice 'this is nice' file1
        !            68: 
        !            69: xset user.foo foo file2
        !            70: xset user.bar bar file2
        !            71: xset user.long 'a long attribute for our new file that tests to ensure that this works' file2
        !            72: 
        !            73: xset user.dir1 'need to test directory xattrs too' foo
        !            74: xset user.dir2 'another xattr' foo
        !            75: xset user.dir3 'this is one last one for the moment' foo
        !            76: 
        !            77: xset user.dir4 'another dir test' foo/bar
        !            78: xset user.dir5 'one last one' foo/bar
        !            79: 
        !            80: xset user.foo 'new foo' foo/file3 foo/bar/file5
        !            81: xset user.bar 'new bar' foo/file3 foo/bar/file5
        !            82: xset user.long 'this is also a long attribute that will be truncated in the initial data send' foo/file3 foo/bar/file5
        !            83: xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' foo/file3 foo/bar/file5
        !            84: 
        !            85: xset user.dir0 'old extra value' "$chkdir/foo"
        !            86: xset user.dir1 'old dir value' "$chkdir/foo"
        !            87: 
        !            88: xset user.short 'old short' "$chkdir/file1"
        !            89: xset user.extra 'remove me' "$chkdir/file1"
        !            90: 
        !            91: xset user.foo 'old foo' "$chkdir/foo/file3"
        !            92: xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' "$chkdir/foo/file3"
        !            93: 
        !            94: case $0 in
        !            95: *hlink*)
        !            96:     ln foo/bar/file5 foo/bar/file6 || test_skipped "Can't create hardlink"
        !            97:     files="$files foo/bar/file6"
        !            98:     dashH='-H'
        !            99:     altDest='--link-dest'
        !           100:     ;;
        !           101: *)
        !           102:     dashH=''
        !           103:     altDest='--copy-dest'
        !           104:     ;;
        !           105: esac
        !           106: 
        !           107: xls $dirs $files >"$scratchdir/xattrs.txt"
        !           108: 
        !           109: # OK, let's try a simple xattr copy.
        !           110: checkit "$RSYNC -avX $dashH --super . '$chkdir/'" "$fromdir" "$chkdir"
        !           111: 
        !           112: cd "$chkdir"
        !           113: xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
        !           114: 
        !           115: cd "$fromdir"
        !           116: 
        !           117: if [ "$dashH" ]; then
        !           118:     for fn in $files; do
        !           119:        name=`basename $fn`
        !           120:        ln $fn ../lnk/$name
        !           121:     done
        !           122: fi
        !           123: 
        !           124: checkit "$RSYNC -aiX $dashH --super $altDest=../chk . ../to" "$fromdir" "$todir"
        !           125: 
        !           126: cd "$todir"
        !           127: xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
        !           128: 
        !           129: [ "$dashH" ] && rm -rf "$lnkdir"
        !           130: 
        !           131: cd "$fromdir"
        !           132: rm -rf "$todir"
        !           133: 
        !           134: xset user.nice 'this is nice, but different' file1
        !           135: 
        !           136: xls $dirs $files >"$scratchdir/xattrs.txt"
        !           137: 
        !           138: checkit "$RSYNC -aiX $dashH --fake-super --link-dest=../chk . ../to" "$chkdir" "$todir"
        !           139: 
        !           140: cd "$todir"
        !           141: xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
        !           142: 
        !           143: sed -n -e '/^[^ ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*  *1 /p' "$scratchdir/ls-to" >"$scratchdir/ls-diff-all"
        !           144: fgrep -v './file1' "$scratchdir/ls-diff-all" >"$scratchdir/ls-diff" || :
        !           145: if [ -s "$scratchdir/ls-diff" ]; then
        !           146:     echo "Missing hard links on:"
        !           147:     cat "$scratchdir/ls-diff"
        !           148:     exit 1
        !           149: fi
        !           150: if [ ! -s "$scratchdir/ls-diff-all" ]; then
        !           151:     echo "Too many hard links on file1!"
        !           152:     exit 1
        !           153: fi
        !           154: 
        !           155: cd "$chkdir"
        !           156: chmod go-rwx . $dirs $files
        !           157: 
        !           158: xset user.nice 'this is nice, but different' file1
        !           159: xset $RSYNC_PREFIX.%stat "40000 0,0 $uid_gid" $dirs
        !           160: xset $RSYNC_PREFIX.%stat "100000 0,0 $uid_gid" $files
        !           161: 
        !           162: xls $dirs $files >"$scratchdir/xattrs.txt"
        !           163: 
        !           164: cd "$fromdir"
        !           165: rm -rf "$todir"
        !           166: 
        !           167: # When run by a non-root tester, this checks if no-user-perm files/dirs can be copied.
        !           168: checkit "$RSYNC -aiX $dashH --fake-super --chmod=a= . ../to" "$chkdir" "$todir" # 2>"$scratchdir/errors.txt"
        !           169: 
        !           170: cd "$todir"
        !           171: xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
        !           172: 
        !           173: cd "$fromdir"
        !           174: rm -rf "$todir" "$chkdir"
        !           175: 
        !           176: $RSYNC -aX file1 file2
        !           177: $RSYNC -aX file1 file2 ../chk/
        !           178: $RSYNC -aX --del ../chk/ .
        !           179: $RSYNC -aX file1 ../lnk/
        !           180: [ "$dashH" ] && ln "$chkdir/file1" ../lnk/extra-link
        !           181: 
        !           182: xls file1 file2 >"$scratchdir/xattrs.txt"
        !           183: 
        !           184: checkit "$RSYNC -aiiX $dashH $altDest=../lnk . ../to" "$chkdir" "$todir"
        !           185: 
        !           186: [ "$dashH" ] && rm ../lnk/extra-link
        !           187: 
        !           188: cd "$todir"
        !           189: xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
        !           190: 
        !           191: cd "$fromdir"
        !           192: rm "$todir/file2"
        !           193: 
        !           194: echo extra >file1
        !           195: $RSYNC -aX . ../chk/
        !           196: 
        !           197: checkit "$RSYNC -aiiX . ../to" "$chkdir" "$todir"
        !           198: 
        !           199: cd "$todir"
        !           200: xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
        !           201: 
        !           202: # The script would have aborted on error, so getting here means we've won.
        !           203: exit 0

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