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