tar.tests 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. # Copyright 2009 by Denys Vlasenko
  3. # Licensed under GPL v2, see file LICENSE for details.
  4. . ./testing.sh
  5. rm -rf tar.tempdir 2>/dev/null
  6. mkdir tar.tempdir && cd tar.tempdir || exit 1
  7. # testing "test name" "script" "expected result" "file input" "stdin"
  8. testing "tar hardlinks and repeated files" '\
  9. rm -rf input_* test.tar 2>/dev/null
  10. >input_hard1
  11. ln input_hard1 input_hard2
  12. mkdir input_dir
  13. >input_dir/file
  14. chmod -R 644 *
  15. chmod 755 input_dir
  16. tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
  17. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  18. tar xf test.tar 2>&1
  19. echo Ok: $?
  20. ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  21. ' "\
  22. input
  23. input_dir/
  24. input_dir/file
  25. input_hard1
  26. input_hard2 -> input_hard1
  27. input_hard1 -> input_hard1
  28. input_dir/
  29. input_dir/file
  30. input
  31. Ok: 0
  32. -rw-r--r-- input_dir/file
  33. drwxr-xr-x input_dir
  34. -rw-r--r-- input_hard1
  35. -rw-r--r-- input_hard2
  36. " \
  37. "" ""
  38. testing "tar hardlinks mode" '\
  39. rm -rf input_* test.tar 2>/dev/null
  40. >input_hard1
  41. chmod 741 input_hard1
  42. ln input_hard1 input_hard2
  43. mkdir input_dir
  44. chmod 550 input_dir
  45. ln input_hard1 input_dir
  46. ln input_hard2 input_dir
  47. tar cf test.tar input_*
  48. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  49. tar xf test.tar 2>&1
  50. echo Ok: $?
  51. ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  52. ' "\
  53. input_dir/
  54. input_dir/input_hard1
  55. input_dir/input_hard2 -> input_dir/input_hard1
  56. input_hard1 -> input_dir/input_hard1
  57. input_hard2 -> input_dir/input_hard1
  58. Ok: 0
  59. -rwxr----x input_dir/input_hard1
  60. -rwxr----x input_dir/input_hard2
  61. dr-xr-x--- input_dir
  62. -rwxr----x input_hard1
  63. -rwxr----x input_hard2
  64. " \
  65. "" ""
  66. testing "tar symlinks mode" '\
  67. rm -rf input_* test.tar 2>/dev/null
  68. >input_file
  69. chmod 741 input_file
  70. ln -s input_file input_soft
  71. mkdir input_dir
  72. chmod 550 input_dir
  73. ln input_file input_dir
  74. ln input_soft input_dir
  75. tar cf test.tar input_*
  76. tar tvf test.tar | sed "s/.*[0-9] input/input/"
  77. tar xf test.tar 2>&1
  78. echo Ok: $?
  79. ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  80. ' "\
  81. input_dir/
  82. input_dir/input_file
  83. input_dir/input_soft -> input_file
  84. input_file -> input_dir/input_file
  85. input_soft -> input_dir/input_soft
  86. Ok: 0
  87. -rwxr----x input_dir/input_file
  88. lrwxrwxrwx input_file
  89. dr-xr-x--- input_dir
  90. -rwxr----x input_file
  91. lrwxrwxrwx input_file
  92. " \
  93. "" ""
  94. optional FEATURE_TAR_LONG_OPTIONS
  95. testing "tar --overwrite" "\
  96. rm -rf input_* test.tar 2>/dev/null
  97. ln input input_hard
  98. tar cf test.tar input_hard
  99. echo WRONG >input
  100. # --overwrite opens 'input_hard' without unlinking,
  101. # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
  102. tar xf test.tar --overwrite 2>&1 && cat input
  103. " "\
  104. Ok
  105. " \
  106. "Ok\n" ""
  107. SKIP=
  108. cd .. && rm -rf tar.tempdir || exit 1
  109. exit $FAILCOUNT