source: branches/3.2/mindi-busybox/testsuite/tar.tests @ 3232

Last change on this file since 3232 was 3232, checked in by bruno, 6 years ago
  • Update mindi-busybox to 1.21.1
  • Property svn:executable set to *
File size: 5.1 KB
Line 
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
7unset LANG
8unset LANGUAGE
9unset LC_COLLATE
10unset LC_ALL
11umask 022
12
13rm -rf tar.tempdir 2>/dev/null
14mkdir tar.tempdir && cd tar.tempdir || exit 1
15
16# testing "test name" "script" "expected result" "file input" "stdin"
17
18optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
19testing "tar hardlinks and repeated files" '\
20rm -rf input_* test.tar 2>/dev/null
21>input_hard1
22ln input_hard1 input_hard2
23mkdir input_dir
24>input_dir/file
25chmod -R 644 *
26chmod    755 input_dir
27tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
28tar tvf test.tar | sed "s/.*[0-9] input/input/"
29tar xf test.tar 2>&1
30echo Ok: $?
31ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
32' "\
33input
34input_dir/
35input_dir/file
36input_hard1
37input_hard2 -> input_hard1
38input_hard1 -> input_hard1
39input_dir/
40input_dir/file
41input
42Ok: 0
43-rw-r--r-- input_dir/file
44drwxr-xr-x input_dir
45-rw-r--r-- input_hard1
46-rw-r--r-- input_hard2
47" \
48"" ""
49SKIP=
50
51optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
52testing "tar hardlinks mode" '\
53rm -rf input_* test.tar 2>/dev/null
54>input_hard1
55chmod 741 input_hard1
56ln input_hard1 input_hard2
57mkdir input_dir
58ln input_hard1 input_dir
59ln input_hard2 input_dir
60chmod 550 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_*":
63tar cf test.tar input_dir/input_hard* input_hard*
64tar tvf test.tar | sed "s/.*[0-9] input/input/"
65chmod 770 input_dir
66rm -rf input_*
67tar xf test.tar 2>&1
68echo Ok: $?
69ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
70' "\
71input_dir/input_hard1
72input_dir/input_hard2 -> input_dir/input_hard1
73input_hard1 -> input_dir/input_hard1
74input_hard2 -> input_dir/input_hard1
75Ok: 0
76-rwxr----x input_dir/input_hard1
77-rwxr----x input_dir/input_hard2
78-rwxr----x input_hard1
79-rwxr----x input_hard2
80" \
81"" ""
82SKIP=
83
84optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
85testing "tar symlinks mode" '\
86rm -rf input_* test.tar 2>/dev/null
87>input_file
88chmod 741 input_file
89ln -s input_file input_soft
90mkdir input_dir
91ln input_file input_dir
92ln input_soft input_dir
93chmod 550 input_dir
94tar cf test.tar input_dir/* input_[fs]*
95tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
96chmod 770 input_dir
97rm -rf input_*
98tar xf test.tar 2>&1
99echo Ok: $?
100ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
101' "\
102input_dir/input_file
103input_dir/input_soft -> input_file
104input_file -> input_dir/input_file
105input_soft -> input_dir/input_soft
106Ok: 0
107-rwxr----x input_dir/input_file
108lrwxrwxrwx input_file
109-rwxr----x input_file
110lrwxrwxrwx input_file
111" \
112"" ""
113SKIP=
114
115optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
116testing "tar --overwrite" "\
117rm -rf input_* test.tar 2>/dev/null
118ln input input_hard
119tar cf test.tar input_hard
120echo WRONG >input
121# --overwrite opens 'input_hard' without unlinking,
122# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
123tar xf test.tar --overwrite 2>&1 && cat input
124" "\
125Ok
126" \
127"Ok\n" ""
128SKIP=
129
130test x"$SKIP_KNOWN_BUGS" = x"" && {
131# Needs to be run under non-root for meaningful test
132optional FEATURE_TAR_CREATE
133testing "tar writing into read-only dir" '\
134rm -rf input_* test.tar 2>/dev/null
135mkdir input_dir
136>input_dir/input_file
137chmod 550 input_dir
138tar cf test.tar input_dir
139tar tvf test.tar | sed "s/.*[0-9] input/input/"
140chmod 770 input_dir
141rm -rf input_*
142tar xf test.tar 2>&1
143echo Ok: $?
144ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
145chmod 770 input_dir
146' "\
147input_dir/
148input_dir/input_file
149Ok: 0
150-rw-r--r-- input_dir/input_file
151dr-xr-x--- input_dir
152" \
153"" ""
154SKIP=
155}
156
157# Had a bug where on extract autodetect first "switched off" -z
158# and then failed to recognize .tgz extension
159optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ
160testing "tar extract tgz" "\
161dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
162tar -czf F0.tgz F0
163rm F0
164tar -xzvf F0.tgz && echo Ok
165rm F0 || echo BAD
166" "\
167F0
168Ok
169" \
170"" ""
171SKIP=
172
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")
175optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
176testing "tar extract txz" "\
177uudecode -o input && tar tf input && echo Ok
178" "\
179hello_world
180Ok
181" \
182"" "\
183begin-base64 644 hello_world.txz
184/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
185SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
186Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
187AAAEWVo=
188====
189"
190SKIP=
191
192# On extract, everything up to and including last ".." component is stripped
193optional FEATURE_TAR_CREATE
194testing "tar strips /../ on extract" "\
195rm -rf input_* test.tar 2>/dev/null
196mkdir input_dir
197echo Ok >input_dir/file
198tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
199rm -rf input_* 2>/dev/null
200tar -vxf test.tar 2>&1
201cat input_dir/file 2>&1
202" "\
203tar: removing leading './../tar.tempdir/input_dir/../' from member names
204input_dir/
205input_dir/file
206Ok
207" \
208"" ""
209SKIP=
210
211
212cd .. && rm -rf tar.tempdir || exit 1
213
214exit $FAILCOUNT
Note: See TracBrowser for help on using the repository browser.