trailing-slash.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # On some operating systems, e.g. SunOS-4.1.1_U1 on sun3x,
  3. # rename() doesn't accept trailing slashes.
  4. # Also, ensure that "mv dir non-exist-dir/" works.
  5. # Also, ensure that "cp dir non-exist-dir/" works.
  6. # Copyright (C) 2004-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. mkdir foo || framework_failure_
  20. mv foo/ bar || fail=1
  21. # mv and cp would misbehave for coreutils versions [5.3.0..5.97], 6.0 and 6.1
  22. for cmd in mv 'cp -r'; do
  23. for opt in '' -T -u; do
  24. rm -rf d e || framework_failure_
  25. mkdir d || framework_failure_
  26. $cmd $opt d e/ || fail=1
  27. if test "$cmd" = mv; then
  28. test -d d && fail=1
  29. else
  30. test -d d || fail=1
  31. fi
  32. test -d e || fail=1
  33. done
  34. done
  35. # We would like the erroneous-looking "mv any non-dir/" to fail,
  36. # but with the current implementation, it depends on how the
  37. # underlying rename syscall handles the trailing slash.
  38. # It does fail, as desired, on recent Linux and Solaris systems.
  39. #touch a a2
  40. #returns_ 1 mv a a2/ || fail=1
  41. # Test for a cp-specific diagnostic introduced after coreutils-8.7:
  42. printf '%s\n' \
  43. "cp: cannot create regular file 'no-such/': Not a directory" \
  44. > expected-err
  45. touch b
  46. cp b no-such/ 2> err
  47. # Map "No such file..." diagnostic to the expected "Not a directory"
  48. sed 's/No such file or directory/Not a directory/' err > k && mv k err
  49. compare expected-err err || fail=1
  50. Exit $fail