xattrs.test 5.2 KB

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