chown.test 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /bin/sh
  2. # Copyright (C) 2002 by Martin Pool <mbp@samba.org>
  3. # This program is distributable under the terms of the GNU GPL (see
  4. # COPYING).
  5. # Test that when rsync is running as root and has -a it correctly sets
  6. # the ownership of the destination.
  7. # We don't know what users will be present on this system, so we just
  8. # use random numeric uids and gids.
  9. . "$suitedir/rsync.fns"
  10. case $0 in
  11. *fake*)
  12. $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests"
  13. RSYNC="$RSYNC --fake-super"
  14. TLS_ARGS="$TLS_ARGS --fake-super"
  15. case "`xattr 2>&1`" in
  16. *--list:*)
  17. chown() {
  18. own=$1
  19. shift
  20. xattr -s 'rsync.%stat' "100644 0,0 $own" "${@}"
  21. }
  22. ;;
  23. *)
  24. chown() {
  25. own=$1
  26. shift
  27. setfattr -n 'user.rsync.%stat' -v "100644 0,0 $own" "${@}"
  28. }
  29. ;;
  30. esac
  31. ;;
  32. *)
  33. RSYNC="$RSYNC --super"
  34. case `get_testuid` in
  35. '') ;; # If "id" failed, try to continue...
  36. 0) ;;
  37. *) if [ -f /usr/bin/fakeroot ]; then
  38. echo "Let's try re-running the script under fakeroot..."
  39. exec /usr/bin/fakeroot /bin/sh "$0"
  40. fi
  41. ;;
  42. esac
  43. ;;
  44. esac
  45. # Build some hardlinks
  46. mkdir "$fromdir"
  47. name1="$fromdir/name1"
  48. name2="$fromdir/name2"
  49. echo "This is the file" > "$name1"
  50. echo "This is the other file" > "$name2"
  51. chown 5000:5002 "$name1" || test_skipped "Can't chown (probably need root)"
  52. chown 5001:5003 "$name2" || test_skipped "Can't chown (probably need root)"
  53. cd "$fromdir/.."
  54. checkit "$RSYNC -aHvv from/ to/" "$fromdir" "$todir"
  55. # The script would have aborted on error, so getting here means we've won.
  56. exit 0