part-fail.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # Make sure we give a sensible diagnostic when a cross-device 'mv'
  3. # fails, e.g., because the destination cannot be unlinked.
  4. # This is a bit fragile since it relies on the string used
  5. # for EPERM: 'permission denied'.
  6. # Copyright (C) 2002-2018 Free Software Foundation, Inc.
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  18. print_ver_ mv
  19. skip_if_root_
  20. cleanup_() { t=$other_partition_tmpdir; chmod -R 700 "$t"; rm -rf "$t"; }
  21. . "$abs_srcdir/tests/other-fs-tmpdir"
  22. touch k "$other_partition_tmpdir/k" || framework_failure_
  23. chmod u-w "$other_partition_tmpdir" || framework_failure_
  24. mv -f k "$other_partition_tmpdir" 2> out && fail=1
  25. printf \
  26. "mv: inter-device move failed: '%s' to '%s';"\
  27. ' unable to remove target: Permission denied\n' \
  28. k "$other_partition_tmpdir/k" >exp
  29. # On some (less-compliant) systems, we get EPERM in this case.
  30. # Accept either diagnostic.
  31. cat <<EOF > exp2
  32. mv: cannot move 'k' to '$other_partition_tmpdir/k': Permission denied
  33. EOF
  34. if cmp out exp >/dev/null 2>&1; then
  35. :
  36. else
  37. if cmp out exp2; then
  38. :
  39. else
  40. fail=1
  41. fi
  42. fi
  43. test $fail = 1 && compare exp out
  44. Exit $fail