fix a copy/paste error in last tar testcase name
[oweals/busybox.git] / testsuite / tar.tests
1 #!/bin/sh
2 # Copyright 2009 by Denys Vlasenko
3 # Licensed under GPLv2, see file LICENSE in this source tree.
4
5 . ./testing.sh
6
7 unset LANG
8 unset LANGUAGE
9 unset LC_COLLATE
10 unset LC_ALL
11 umask 022
12
13 rm -rf tar.tempdir 2>/dev/null
14 mkdir tar.tempdir && cd tar.tempdir || exit 1
15
16 # testing "test name" "script" "expected result" "file input" "stdin"
17
18 optional FEATURE_SEAMLESS_GZ
19 testing "Empty file is not a tarball.tar.gz" '\
20 tar xvzf - 2>&1; echo $?
21 ' "\
22 tar: invalid magic
23 tar: short read
24 1
25 " \
26 "" ""
27 SKIP=
28
29 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
30 testing "tar hardlinks and repeated files" '\
31 rm -rf input_* test.tar 2>/dev/null
32 >input_hard1
33 ln input_hard1 input_hard2
34 mkdir input_dir
35 >input_dir/file
36 chmod -R 644 *
37 chmod    755 input_dir
38 tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
39 tar tvf test.tar | sed "s/.*[0-9] input/input/"
40 tar xf test.tar 2>&1
41 echo Ok: $?
42 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
43 ' "\
44 input
45 input_dir/
46 input_dir/file
47 input_hard1
48 input_hard2 -> input_hard1
49 input_hard1 -> input_hard1
50 input_dir/
51 input_dir/file
52 input
53 Ok: 0
54 -rw-r--r-- input_dir/file
55 drwxr-xr-x input_dir
56 -rw-r--r-- input_hard1
57 -rw-r--r-- input_hard2
58 " \
59 "" ""
60 SKIP=
61
62 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
63 testing "tar hardlinks mode" '\
64 rm -rf input_* test.tar 2>/dev/null
65 >input_hard1
66 chmod 741 input_hard1
67 ln input_hard1 input_hard2
68 mkdir input_dir
69 ln input_hard1 input_dir
70 ln input_hard2 input_dir
71 chmod 550 input_dir
72 # On some filesystems, input_dir/input_hard2 is returned by readdir
73 # BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
74 tar cf test.tar input_dir/input_hard* input_hard*
75 tar tvf test.tar | sed "s/.*[0-9] input/input/"
76 chmod 770 input_dir
77 rm -rf input_*
78 tar xf test.tar 2>&1
79 echo Ok: $?
80 ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
81 ' "\
82 input_dir/input_hard1
83 input_dir/input_hard2 -> input_dir/input_hard1
84 input_hard1 -> input_dir/input_hard1
85 input_hard2 -> input_dir/input_hard1
86 Ok: 0
87 -rwxr----x input_dir/input_hard1
88 -rwxr----x input_dir/input_hard2
89 -rwxr----x input_hard1
90 -rwxr----x input_hard2
91 " \
92 "" ""
93 SKIP=
94
95 optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
96 testing "tar symlinks mode" '\
97 rm -rf input_* test.tar 2>/dev/null
98 >input_file
99 chmod 741 input_file
100 ln -s input_file input_soft
101 mkdir input_dir
102 ln input_file input_dir
103 ln input_soft input_dir
104 chmod 550 input_dir
105 tar cf test.tar input_dir/* input_[fs]*
106 tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
107 chmod 770 input_dir
108 rm -rf input_*
109 tar xf test.tar 2>&1
110 echo Ok: $?
111 ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
112 ' "\
113 input_dir/input_file
114 input_dir/input_soft -> input_file
115 input_file -> input_dir/input_file
116 input_soft -> input_dir/input_soft
117 Ok: 0
118 -rwxr----x input_dir/input_file
119 lrwxrwxrwx input_file
120 -rwxr----x input_file
121 lrwxrwxrwx input_file
122 " \
123 "" ""
124 SKIP=
125
126 optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
127 testing "tar --overwrite" "\
128 rm -rf input_* test.tar 2>/dev/null
129 ln input input_hard
130 tar cf test.tar input_hard
131 echo WRONG >input
132 # --overwrite opens 'input_hard' without unlinking,
133 # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
134 tar xf test.tar --overwrite 2>&1 && cat input
135 " "\
136 Ok
137 " \
138 "Ok\n" ""
139 SKIP=
140
141 test x"$SKIP_KNOWN_BUGS" = x"" && {
142 # Needs to be run under non-root for meaningful test
143 optional FEATURE_TAR_CREATE
144 testing "tar writing into read-only dir" '\
145 rm -rf input_* test.tar 2>/dev/null
146 mkdir input_dir
147 >input_dir/input_file
148 chmod 550 input_dir
149 tar cf test.tar input_dir
150 tar tvf test.tar | sed "s/.*[0-9] input/input/"
151 chmod 770 input_dir
152 rm -rf input_*
153 tar xf test.tar 2>&1
154 echo Ok: $?
155 ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
156 chmod 770 input_dir
157 ' "\
158 input_dir/
159 input_dir/input_file
160 Ok: 0
161 -rw-r--r-- input_dir/input_file
162 dr-xr-x--- input_dir
163 " \
164 "" ""
165 SKIP=
166 }
167
168 # Had a bug where on extract autodetect first "switched off" -z
169 # and then failed to recognize .tgz extension
170 optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ
171 testing "tar extract tgz" "\
172 dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
173 tar -czf F0.tgz F0
174 rm F0
175 tar -xzvf F0.tgz && echo Ok
176 rm F0 || echo BAD
177 " "\
178 F0
179 Ok
180 " \
181 "" ""
182 SKIP=
183
184 # Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)?
185 # (the uuencoded hello_world.txz contains one empty file named "hello_world")
186 optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
187 testing "tar extract txz" "\
188 uudecode -o input && tar tf input && echo Ok
189 " "\
190 hello_world
191 Ok
192 " \
193 "" "\
194 begin-base64 644 hello_world.txz
195 /Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
196 SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
197 Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
198 AAAEWVo=
199 ====
200 "
201 SKIP=
202
203 # On extract, everything up to and including last ".." component is stripped
204 optional FEATURE_TAR_CREATE
205 testing "tar strips /../ on extract" "\
206 rm -rf input_* test.tar 2>/dev/null
207 mkdir input_dir
208 echo Ok >input_dir/file
209 tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
210 rm -rf input_* 2>/dev/null
211 tar -vxf test.tar 2>&1
212 cat input_dir/file 2>&1
213 " "\
214 tar: removing leading './../tar.tempdir/input_dir/../' from member names
215 input_dir/
216 input_dir/file
217 Ok
218 " \
219 "" ""
220 SKIP=
221
222
223 cd .. && rm -rf tar.tempdir || exit 1
224
225 exit $FAILCOUNT