tar.tests 2.9 KB

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