2 # Copyright 2009 by Denys Vlasenko
3 # Licensed under GPLv2, see file LICENSE in this source tree.
13 rm -rf tar.tempdir 2>/dev/null
14 mkdir tar.tempdir && cd tar.tempdir || exit 1
16 # testing "test name" "script" "expected result" "file input" "stdin"
18 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
19 testing "tar hardlinks and repeated files" '\
20 rm -rf input_* test.tar 2>/dev/null
22 ln input_hard1 input_hard2
27 tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
28 tar tvf test.tar | sed "s/.*[0-9] input/input/"
31 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
37 input_hard2 -> input_hard1
38 input_hard1 -> input_hard1
43 -rw-r--r-- input_dir/file
45 -rw-r--r-- input_hard1
46 -rw-r--r-- input_hard2
51 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
52 testing "tar hardlinks mode" '\
53 rm -rf input_* test.tar 2>/dev/null
56 ln input_hard1 input_hard2
58 ln input_hard1 input_dir
59 ln input_hard2 input_dir
61 # On some filesystems, input_dir/input_hard2 is returned by readdir
62 # BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
63 tar cf test.tar input_dir/input_hard* input_hard*
64 tar tvf test.tar | sed "s/.*[0-9] input/input/"
69 ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
72 input_dir/input_hard2 -> input_dir/input_hard1
73 input_hard1 -> input_dir/input_hard1
74 input_hard2 -> input_dir/input_hard1
76 -rwxr----x input_dir/input_hard1
77 -rwxr----x input_dir/input_hard2
78 -rwxr----x input_hard1
79 -rwxr----x input_hard2
84 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
85 testing "tar symlinks mode" '\
86 rm -rf input_* test.tar 2>/dev/null
89 ln -s input_file input_soft
91 ln input_file input_dir
92 ln input_soft input_dir
94 tar cf test.tar input_dir/* input_[fs]*
95 tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
100 ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
103 input_dir/input_soft -> input_file
104 input_file -> input_dir/input_file
105 input_soft -> input_dir/input_soft
107 -rwxr----x input_dir/input_file
108 lrwxrwxrwx input_file
109 -rwxr----x input_file
110 lrwxrwxrwx input_file
115 optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
116 testing "tar --overwrite" "\
117 rm -rf input_* test.tar 2>/dev/null
119 tar cf test.tar input_hard
121 # --overwrite opens 'input_hard' without unlinking,
122 # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
123 tar xf test.tar --overwrite 2>&1 && cat input
130 test x"$SKIP_KNOWN_BUGS" = x"" && {
131 # Needs to be run under non-root for meaningful test
132 optional FEATURE_TAR_CREATE
133 testing "tar writing into read-only dir" '\
134 rm -rf input_* test.tar 2>/dev/null
136 >input_dir/input_file
138 tar cf test.tar input_dir
139 tar tvf test.tar | sed "s/.*[0-9] input/input/"
144 ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
150 -rw-r--r-- input_dir/input_file
157 # Had a bug where on extract autodetect first "switched off" -z
158 # and then failed to recognize .tgz extension
159 optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ
160 testing "tar extract tgz" "\
161 dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
164 tar -xzvf F0.tgz && echo Ok
173 # Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)?
174 # (the uuencoded hello_world.txz contains one empty file named "hello_world")
175 optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
176 testing "tar extract txz" "\
177 uudecode -o input && tar tf input && echo Ok
183 begin-base64 644 hello_world.txz
184 /Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
185 SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
186 Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
192 # On extract, everything up to and including last ".." component is stripped
193 optional FEATURE_TAR_CREATE
194 testing "tar strips /../ on extract" "\
195 rm -rf input_* test.tar 2>/dev/null
197 echo Ok >input_dir/file
198 tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
199 rm -rf input_* 2>/dev/null
200 tar -vxf test.tar 2>&1
201 cat input_dir/file 2>&1
203 tar: removing leading './../tar.tempdir/input_dir/../' from member names
212 cd .. && rm -rf tar.tempdir || exit 1