hard-2.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # Ensure that moving hard-linked arguments onto existing destinations works.
  3. # Likewise when using cp --preserve=link.
  4. # Copyright (C) 2003-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  16. print_ver_ cp mv
  17. skip_if_root_
  18. mkdir dst || framework_failure_
  19. (cd dst && touch a b c) || framework_failure_
  20. touch a || framework_failure_
  21. ln a b || framework_failure_
  22. ln a c || framework_failure_
  23. # ======================================
  24. cp --preserve=link a b c dst || fail=1
  25. # The source files must remain.
  26. test -f a || fail=1
  27. test -f b || fail=1
  28. test -f c || fail=1
  29. cd dst
  30. # Three destination files must exist.
  31. test -f a || fail=1
  32. test -f b || fail=1
  33. test -f c || fail=1
  34. # The three i-node numbers must be the same.
  35. ia=$(ls -i a|sed 's/ a//')
  36. ib=$(ls -i b|sed 's/ b//')
  37. ic=$(ls -i c|sed 's/ c//')
  38. test $ia = $ib || fail=1
  39. test $ia = $ic || fail=1
  40. cd ..
  41. rm -f dst/[abc]
  42. (cd dst && touch a b c)
  43. # ======================================
  44. mv a b c dst || fail=1
  45. # The source files must be gone.
  46. test -f a && fail=1
  47. test -f b && fail=1
  48. test -f c && fail=1
  49. cd dst
  50. # Three destination files must exist.
  51. test -f a || fail=1
  52. test -f b || fail=1
  53. test -f c || fail=1
  54. # The three i-node numbers must be the same.
  55. ia=$(ls -i a|sed 's/ a//')
  56. ib=$(ls -i b|sed 's/ b//')
  57. ic=$(ls -i c|sed 's/ c//')
  58. test $ia = $ib || fail=1
  59. test $ia = $ic || fail=1
  60. Exit $fail