tar.tests 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/sh
  2. # Copyright 2009 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. unset LANG
  6. unset LANGUAGE
  7. unset LC_COLLATE
  8. unset LC_ALL
  9. umask 022
  10. rm -rf tar.tempdir 2>/dev/null
  11. mkdir tar.tempdir && cd tar.tempdir || exit 1
  12. # testing "test name" "script" "expected result" "file input" "stdin"
  13. optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  14. testing "tar hardlinks and repeated files" '\
  15. rm -rf input_* test.tar 2>/dev/null
  16. >input_hard1
  17. ln input_hard1 input_hard2
  18. mkdir input_dir
  19. >input_dir/file
  20. chmod -R 644 *
  21. chmod 755 input_dir
  22. tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
  23. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  24. tar xf test.tar 2>&1
  25. echo Ok: $?
  26. ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  27. ' "\
  28. input
  29. input_dir/
  30. input_dir/file
  31. input_hard1
  32. input_hard2 -> input_hard1
  33. input_hard1 -> input_hard1
  34. input_dir/
  35. input_dir/file
  36. input
  37. Ok: 0
  38. -rw-r--r-- input_dir/file
  39. drwxr-xr-x input_dir
  40. -rw-r--r-- input_hard1
  41. -rw-r--r-- input_hard2
  42. " \
  43. "" ""
  44. SKIP=
  45. optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  46. testing "tar hardlinks mode" '\
  47. rm -rf input_* test.tar 2>/dev/null
  48. >input_hard1
  49. chmod 741 input_hard1
  50. ln input_hard1 input_hard2
  51. mkdir input_dir
  52. ln input_hard1 input_dir
  53. ln input_hard2 input_dir
  54. chmod 550 input_dir
  55. # On some filesystems, input_dir/input_hard2 is returned by readdir
  56. # BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
  57. tar cf test.tar input_dir/input_hard* input_hard*
  58. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  59. chmod 770 input_dir
  60. rm -rf input_*
  61. tar xf test.tar 2>&1
  62. echo Ok: $?
  63. ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  64. ' "\
  65. input_dir/input_hard1
  66. input_dir/input_hard2 -> input_dir/input_hard1
  67. input_hard1 -> input_dir/input_hard1
  68. input_hard2 -> input_dir/input_hard1
  69. Ok: 0
  70. -rwxr----x input_dir/input_hard1
  71. -rwxr----x input_dir/input_hard2
  72. -rwxr----x input_hard1
  73. -rwxr----x input_hard2
  74. " \
  75. "" ""
  76. SKIP=
  77. optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  78. testing "tar symlinks mode" '\
  79. rm -rf input_* test.tar 2>/dev/null
  80. >input_file
  81. chmod 741 input_file
  82. ln -s input_file input_soft
  83. mkdir input_dir
  84. ln input_file input_dir
  85. ln input_soft input_dir
  86. chmod 550 input_dir
  87. tar cf test.tar input_dir/* input_[fs]*
  88. tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
  89. chmod 770 input_dir
  90. rm -rf input_*
  91. tar xf test.tar 2>&1
  92. echo Ok: $?
  93. ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  94. ' "\
  95. input_dir/input_file
  96. input_dir/input_soft -> input_file
  97. input_file -> input_dir/input_file
  98. input_soft -> input_dir/input_soft
  99. Ok: 0
  100. -rwxr----x input_dir/input_file
  101. lrwxrwxrwx input_file
  102. -rwxr----x input_file
  103. lrwxrwxrwx input_file
  104. " \
  105. "" ""
  106. SKIP=
  107. optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
  108. testing "tar --overwrite" "\
  109. rm -rf input_* test.tar 2>/dev/null
  110. ln input input_hard
  111. tar cf test.tar input_hard
  112. echo WRONG >input
  113. # --overwrite opens 'input_hard' without unlinking,
  114. # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
  115. tar xf test.tar --overwrite 2>&1 && cat input
  116. " "\
  117. Ok
  118. " \
  119. "Ok\n" ""
  120. SKIP=
  121. test x"$SKIP_KNOWN_BUGS" = x"" && {
  122. # Needs to be run under non-root for meaningful test
  123. optional FEATURE_TAR_CREATE
  124. testing "tar writing into read-only dir" '\
  125. rm -rf input_* test.tar 2>/dev/null
  126. mkdir input_dir
  127. >input_dir/input_file
  128. chmod 550 input_dir
  129. tar cf test.tar input_dir
  130. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  131. chmod 770 input_dir
  132. rm -rf input_*
  133. tar xf test.tar 2>&1
  134. echo Ok: $?
  135. ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  136. chmod 770 input_dir
  137. ' "\
  138. input_dir/
  139. input_dir/input_file
  140. Ok: 0
  141. -rw-r--r-- input_dir/input_file
  142. dr-xr-x--- input_dir
  143. " \
  144. "" ""
  145. SKIP=
  146. }
  147. # Had a bug where on extract autodetect first "switched off" -z
  148. # and then failed to recognize .tgz extension
  149. optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ
  150. testing "tar extract tgz" "\
  151. dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
  152. tar -czf F0.tgz F0
  153. rm F0
  154. tar -xzvf F0.tgz && echo Ok
  155. rm F0 || echo BAD
  156. " "\
  157. F0
  158. Ok
  159. " \
  160. "" ""
  161. SKIP=
  162. # On extract, everything up to and including last ".." component is stripped
  163. optional FEATURE_TAR_CREATE
  164. testing "tar strips /../ on extract" "\
  165. rm -rf input_* test.tar 2>/dev/null
  166. mkdir input_dir
  167. echo Ok >input_dir/file
  168. tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
  169. rm -rf input_* 2>/dev/null
  170. tar -vxf test.tar 2>&1
  171. cat input_dir/file 2>&1
  172. " "\
  173. tar: removing leading './../tar.tempdir/input_dir/../' from member names
  174. input_dir/
  175. input_dir/file
  176. Ok
  177. " \
  178. "" ""
  179. SKIP=
  180. cd .. && rm -rf tar.tempdir || exit 1
  181. exit $FAILCOUNT