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 testing "Empty file is not a tarball" '\
19 tar xvf - 2>&1; echo $?
27 optional FEATURE_SEAMLESS_GZ
28 # In NOMMU case, "invalid magic" message comes from gunzip child process.
29 # Otherwise, it comes from tar.
30 # Need to fix output up to avoid false positive.
31 testing "Empty file is not a tarball.tar.gz" '\
32 { tar xvzf - 2>&1; echo $?; } | grep -Fv "invalid magic"
40 testing "Two zeroed blocks is a ('truncated') empty tarball" '\
41 dd if=/dev/zero bs=512 count=2 2>/dev/null | tar xvf - 2>&1; echo $?
48 testing "Twenty zeroed blocks is an empty tarball" '\
49 dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $?
56 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
57 testing "tar hardlinks and repeated files" '\
58 rm -rf input_* test.tar 2>/dev/null
60 ln input_hard1 input_hard2
65 tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
66 tar tvf test.tar | sed "s/.*[0-9] input/input/"
69 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
75 input_hard2 -> input_hard1
76 input_hard1 -> input_hard1
81 -rw-r--r-- input_dir/file
83 -rw-r--r-- input_hard1
84 -rw-r--r-- input_hard2
89 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
90 testing "tar hardlinks mode" '\
91 rm -rf input_* test.tar 2>/dev/null
94 ln input_hard1 input_hard2
96 ln input_hard1 input_dir
97 ln input_hard2 input_dir
99 # On some filesystems, input_dir/input_hard2 is returned by readdir
100 # BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
101 tar cf test.tar input_dir/input_hard* input_hard*
102 tar tvf test.tar | sed "s/.*[0-9] input/input/"
107 ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
109 input_dir/input_hard1
110 input_dir/input_hard2 -> input_dir/input_hard1
111 input_hard1 -> input_dir/input_hard1
112 input_hard2 -> input_dir/input_hard1
114 -rwxr----x input_dir/input_hard1
115 -rwxr----x input_dir/input_hard2
116 -rwxr----x input_hard1
117 -rwxr----x input_hard2
122 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
123 testing "tar symlinks mode" '\
124 rm -rf input_* test.tar 2>/dev/null
127 ln -s input_file input_soft
129 ln input_file input_dir
130 ln input_soft input_dir
132 tar cf test.tar input_dir/* input_[fs]*
133 tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
138 ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
141 input_dir/input_soft -> input_file
142 input_file -> input_dir/input_file
143 input_soft -> input_dir/input_soft
145 -rwxr----x input_dir/input_file
146 lrwxrwxrwx input_file
147 -rwxr----x input_file
148 lrwxrwxrwx input_file
153 optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
154 testing "tar --overwrite" "\
155 rm -rf input_* test.tar 2>/dev/null
157 tar cf test.tar input_hard
159 # --overwrite opens 'input_hard' without unlinking,
160 # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
161 tar xf test.tar --overwrite 2>&1 && cat input
168 test x"$SKIP_KNOWN_BUGS" = x"" && {
169 # Needs to be run under non-root for meaningful test
170 optional FEATURE_TAR_CREATE
171 testing "tar writing into read-only dir" '\
172 rm -rf input_* test.tar 2>/dev/null
174 >input_dir/input_file
176 tar cf test.tar input_dir
177 tar tvf test.tar | sed "s/.*[0-9] input/input/"
182 ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
188 -rw-r--r-- input_dir/input_file
195 # Had a bug where on extract autodetect first "switched off" -z
196 # and then failed to recognize .tgz extension
197 optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ
198 testing "tar extract tgz" "\
199 dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
202 tar -xzvf F0.tgz && echo Ok
211 # Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)?
212 # (the uuencoded hello_world.txz contains one empty file named "hello_world")
213 optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
214 testing "tar extract txz" "\
215 uudecode -o input && tar tf input && echo Ok
221 begin-base64 644 hello_world.txz
222 /Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
223 SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
224 Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
230 # On extract, everything up to and including last ".." component is stripped
231 optional FEATURE_TAR_CREATE
232 testing "tar strips /../ on extract" "\
233 rm -rf input_* test.tar 2>/dev/null
235 echo Ok >input_dir/file
236 tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
237 rm -rf input_* 2>/dev/null
238 tar -vxf test.tar 2>&1
239 cat input_dir/file 2>&1
241 tar: removing leading './../tar.tempdir/input_dir/../' from member names
250 cd .. && rm -rf tar.tempdir || exit 1