xattrs.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync is configured without xattr support"
  7. case "`xattr 2>&1`" in
  8. *--list:*)
  9. xset() {
  10. xnam="$1"
  11. xval="$2"
  12. shift 2
  13. xattr -s "$xnam" "$xval" "${@}"
  14. }
  15. xls() {
  16. xattr -l "${@}"
  17. }
  18. RUSR='rsync.nonuser'
  19. ;;
  20. *)
  21. xset() {
  22. xnam="$1"
  23. xval="$2"
  24. shift 2
  25. setfattr -n "$xnam" -v "$xval" "${@}"
  26. }
  27. xls() {
  28. getfattr -d "${@}"
  29. }
  30. RUSR='user.rsync'
  31. ;;
  32. esac
  33. makepath "$fromdir/foo/bar"
  34. echo now >"$fromdir/file0"
  35. echo something >"$fromdir/file1"
  36. echo else >"$fromdir/file2"
  37. echo deep >"$fromdir/foo/file3"
  38. echo normal >"$fromdir/file4"
  39. echo deeper >"$fromdir/foo/bar/file5"
  40. makepath "$chkdir/foo"
  41. echo wow >"$chkdir/file1"
  42. cp_touch "$fromdir/foo/file3" "$chkdir/foo"
  43. files='foo file0 file1 file2 foo/file3 file4 foo/bar/file5'
  44. cd "$fromdir"
  45. xset user.foo foo file0 2>/dev/null || test_skipped "Unable to set an xattr"
  46. xset user.bar bar file0
  47. xset user.short 'this is short' file1
  48. xset user.long 'this is a long attribute that will be truncated in the initial data send' file1
  49. xset user.good 'this is good' file1
  50. xset user.nice 'this is nice' file1
  51. xset user.foo foo file2
  52. xset user.bar bar file2
  53. xset user.long 'a long attribute for our new file that tests to ensure that this works' file2
  54. xset user.dir1 'need to test directory xattrs too' foo
  55. xset user.dir2 'another xattr' foo
  56. xset user.dir3 'this is one last one for the moment' foo
  57. xset user.foo 'new foo' foo/file3 foo/bar/file5
  58. xset user.bar 'new bar' foo/file3 foo/bar/file5
  59. xset user.long 'this is also a long attribute that will be truncated in the initial data send' foo/file3 foo/bar/file5
  60. xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' foo/file3 foo/bar/file5
  61. xset user.short 'old short' "$chkdir/file1"
  62. xset user.extra 'remove me' "$chkdir/file1"
  63. xset user.foo 'old foo' "$chkdir/foo/file3"
  64. xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' "$chkdir/foo/file3"
  65. xls $files >"$scratchdir/xattrs.txt"
  66. # OK, let's try a simple xattr copy.
  67. checkit "$RSYNC -avX --super . '$chkdir/'" "$fromdir" "$chkdir"
  68. cd "$chkdir"
  69. xls $files | diff $diffopt "$scratchdir/xattrs.txt" -
  70. cd "$fromdir"
  71. checkit "$RSYNC -aiX --super --copy-dest=../chk . ../to" "$fromdir" "$todir"
  72. cd "$todir"
  73. xls $files | diff $diffopt "$scratchdir/xattrs.txt" -
  74. cd "$fromdir"
  75. rm -rf "$todir"
  76. xset user.nice 'this is nice, but different' file1
  77. checkit "$RSYNC -aiX --fake-super . ../chk" "$fromdir" "$chkdir"
  78. cd "$chkdir"
  79. xls $files >"$scratchdir/xattrs.txt"
  80. cd "$fromdir"
  81. checkit "$RSYNC -aiX --fake-super --link-dest=../chk . ../to" "$chkdir" "$todir"
  82. cd "$todir"
  83. xls $files | diff $diffopt "$scratchdir/xattrs.txt" -
  84. sed -n -e '/\.\/file1$/d' -e '/^[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *1 /p' "$scratchdir/ls-to" >"$scratchdir/ls-diff"
  85. if [ -s "$scratchdir/ls-diff" ]; then
  86. echo "Missing hard links on:"
  87. cat "$scratchdir/ls-diff"
  88. exit 1
  89. fi
  90. cd "$fromdir"
  91. rm -rf "$todir" "$chkdir"
  92. $RSYNC -aX file1 file2
  93. $RSYNC -aX file1 file2 ../chk/
  94. $RSYNC -aX --del ../chk/ .
  95. $RSYNC -aX file1 ../lnk/
  96. xls file1 file2 >"$scratchdir/xattrs.txt"
  97. checkit "$RSYNC -aiiX --copy-dest=../lnk . ../to" "$chkdir" "$todir"
  98. cd "$todir"
  99. xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
  100. cd "$fromdir"
  101. rm "$todir/file2"
  102. echo extra >file1
  103. $RSYNC -aX . ../chk/
  104. checkit "$RSYNC -aiiX . ../to" "$chkdir" "$todir"
  105. cd "$todir"
  106. xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
  107. # The script would have aborted on error, so getting here means we've won.
  108. exit 0