dup-source.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. # Ensure that cp merely warns when a non-directory source file is
  3. # listed on the command line more than once. fileutils-4.1.1
  4. # made this fail: cp a a d/
  5. # Ensure that mv fails with a similar command.
  6. # Copyright (C) 2001-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_ cp mv
  19. skip_if_root_
  20. reset_files() { rm -fr a b d; touch a; mkdir b d; }
  21. for i in cp; do
  22. # cp may not fail in this case.
  23. reset_files
  24. $i a a d/ 2> out || fail=1
  25. reset_files
  26. $i ./a a d/ 2>> out || fail=1
  27. # Similarly for directories, but handle
  28. # source == dest appropriately.
  29. reset_files
  30. $i -a ./b b d/ 2>> out || fail=1
  31. reset_files
  32. returns_ 1 $i -a ./b b b/ 2>> out || fail=1
  33. # cp succeeds with --backup=numbered.
  34. reset_files
  35. $i --backup=numbered a a d/ 2>> out || fail=1
  36. # But not with plain '--backup'
  37. reset_files
  38. returns_ 1 $i --backup a a d/ 2>> out || fail=1
  39. cat <<EOF > exp
  40. $i: warning: source file 'a' specified more than once
  41. $i: warning: source file 'a' specified more than once
  42. $i: warning: source directory 'b' specified more than once
  43. $i: cannot copy a directory, './b', into itself, 'b/b'
  44. $i: warning: source directory 'b' specified more than once
  45. $i: will not overwrite just-created 'd/a' with 'a'
  46. EOF
  47. compare exp out || fail=1
  48. done
  49. for i in mv; do
  50. # But mv *does* fail in this case (it has to).
  51. reset_files
  52. returns_ 1 $i a a d/ 2> out || fail=1
  53. returns_ 1 test -e a || fail=1
  54. reset_files
  55. returns_ 1 $i ./a a d/ 2>> out || fail=1
  56. returns_ 1 test -e a || fail=1
  57. # Similarly for directories, also handling
  58. # source == dest appropriately.
  59. reset_files
  60. returns_ 1 $i ./b b d/ 2>> out || fail=1
  61. returns_ 1 test -e b || fail=1
  62. reset_files
  63. returns_ 1 $i --verbose ./b b b/ 2>> out || fail=1
  64. test -d b || fail=1
  65. cat <<EOF > exp
  66. $i: cannot stat 'a': No such file or directory
  67. $i: cannot stat 'a': No such file or directory
  68. $i: cannot stat 'b': No such file or directory
  69. $i: cannot move './b' to a subdirectory of itself, 'b/b'
  70. $i: warning: source directory 'b' specified more than once
  71. EOF
  72. compare exp out || fail=1
  73. done
  74. Exit $fail