install-C.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. # Ensure "install -C" works. (basic tests)
  3. # Copyright (C) 2008-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ginstall
  16. skip_if_setgid_
  17. skip_if_nondefault_group_
  18. # Note if a group is not specified, install(1) will assume that a file
  19. # would be installed with the current user's group ID, and thus if the
  20. # file is the same except that it does have a different group due to
  21. # its parent directory being g+s for example, then the copy will be
  22. # done again redundantly in a futile attempt to reset the group ID to
  23. # that of the current user.
  24. #
  25. # install -d -g wheel -m 2775 test # Create setgid dir
  26. # touch test/a # Create source
  27. # install -Cv -m664 test/a test/i1 # install source with mode
  28. # install -Cv -m664 test/i1 test/i2 # install dest
  29. # install -Cv -m664 test/i1 test/i2 # again to see redundant install
  30. #
  31. # Similarly if an existing file exists that is the same and has the
  32. # current users group ID, but when an actual install of the file would
  33. # reset to a different group ID due to the directory being g+s for example,
  34. # then the install will not be done when it should.
  35. #
  36. # install -Cv -m664 -g "$(id -nrg)" test/i1 test/i2 # set i2 to uesr's gid
  37. # install -Cv -m664 test/i1 test/i2 # this should install but doesn't
  38. #
  39. # Therefore we skip the test in the presence of setgid dirs
  40. # An additional complication on HFS is that it...
  41. mode1=0644
  42. mode2=0755
  43. mode3=2755
  44. echo test > a || framework_failure_
  45. echo "'a' -> 'b'" > out_installed_first || framework_failure_
  46. echo "removed 'b'
  47. 'a' -> 'b'" > out_installed_second || framework_failure_
  48. > out_empty || framework_failure_
  49. # destination file does not exist
  50. ginstall -Cv -m$mode1 a b > out || fail=1
  51. compare out out_installed_first || fail=1
  52. # destination file exists
  53. ginstall -Cv -m$mode1 a b > out || fail=1
  54. compare out out_empty || fail=1
  55. # destination file exists (long option)
  56. ginstall -v --compare -m$mode1 a b > out || fail=1
  57. compare out out_empty || fail=1
  58. # destination file exists but -C is not given
  59. ginstall -v -m$mode1 a b > out || fail=1
  60. compare out out_installed_second || fail=1
  61. # option -C ignored if any non-permission mode should be set
  62. ginstall -Cv -m$mode3 a b > out || fail=1
  63. compare out out_installed_second || fail=1
  64. ginstall -Cv -m$mode3 a b > out || fail=1
  65. compare out out_installed_second || fail=1
  66. # files are not regular files
  67. ln -s a c || framework_failure_
  68. ln -s b d || framework_failure_
  69. ginstall -Cv -m$mode1 c d > out || fail=1
  70. echo "removed 'd'
  71. 'c' -> 'd'" > out_installed_second_cd
  72. compare out out_installed_second_cd || fail=1
  73. # destination file exists but content differs
  74. echo test1 > a || framework_failure_
  75. ginstall -Cv -m$mode1 a b > out || fail=1
  76. compare out out_installed_second || fail=1
  77. ginstall -Cv -m$mode1 a b > out || fail=1
  78. compare out out_empty || fail=1
  79. # destination file exists but content differs (same size)
  80. echo test2 > a || framework_failure_
  81. ginstall -Cv -m$mode1 a b > out || fail=1
  82. compare out out_installed_second || fail=1
  83. ginstall -Cv -m$mode1 a b > out || fail=1
  84. compare out out_empty || fail=1
  85. # destination file exists but mode differs
  86. ginstall -Cv -m$mode2 a b > out || fail=1
  87. compare out out_installed_second || fail=1
  88. ginstall -Cv -m$mode2 a b > out || fail=1
  89. compare out out_empty || fail=1
  90. # options -C and --preserve-timestamps are mutually exclusive
  91. returns_ 1 ginstall -C --preserve-timestamps a b || fail=1
  92. # options -C and --strip are mutually exclusive
  93. returns_ 1 ginstall -C --strip --strip-program=echo a b || fail=1
  94. Exit $fail