tar: fix mishandling of repeated hardlink in tarball; expand tests
[oweals/busybox.git] / testsuite / tar.tests
1 #!/bin/sh
2 # Copyright 2009 by Denys Vlasenko
3 # Licensed under GPL v2, see file LICENSE for details.
4
5 . ./testing.sh
6
7 rm -rf tar.tempdir 2>/dev/null
8 mkdir tar.tempdir && cd tar.tempdir || exit 1
9
10 # testing "test name" "script" "expected result" "file input" "stdin"
11
12 testing "tar hardlinks and repeated files" '\
13 rm -rf input_* test.tar 2>/dev/null
14 >input_hard1
15 ln input_hard1 input_hard2
16 mkdir input_dir
17 >input_dir/file
18 chmod -R 644 *
19 chmod    755 input_dir
20 tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
21 tar tvf test.tar | sed "s/.*[0-9] input/input/"
22 tar xf test.tar 2>&1
23 echo Ok: $?
24 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
25 ' "\
26 input
27 input_dir/
28 input_dir/file
29 input_hard1
30 input_hard2 -> input_hard1
31 input_hard1 -> input_hard1
32 input_dir/
33 input_dir/file
34 input
35 Ok: 0
36 -rw-r--r-- input_dir/file
37 drwxr-xr-x input_dir
38 -rw-r--r-- input_hard1
39 -rw-r--r-- input_hard2
40 " \
41 "" ""
42
43 testing "tar hardlinks mode" '\
44 rm -rf input_* test.tar 2>/dev/null
45 >input_hard1
46 chmod 741 input_hard1
47 ln input_hard1 input_hard2
48 mkdir input_dir
49 chmod 550 input_dir
50 ln input_hard1 input_dir
51 ln input_hard2 input_dir
52 tar cf test.tar input_*
53 tar tvf test.tar | sed "s/.*[0-9] input/input/"
54 tar xf test.tar 2>&1
55 echo Ok: $?
56 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
57 ' "\
58 input_dir/
59 input_dir/input_hard1
60 input_dir/input_hard2 -> input_dir/input_hard1
61 input_hard1 -> input_dir/input_hard1
62 input_hard2 -> input_dir/input_hard1
63 Ok: 0
64 -rwxr----x input_dir/input_hard1
65 -rwxr----x input_dir/input_hard2
66 dr-xr-x--- input_dir
67 -rwxr----x input_hard1
68 -rwxr----x input_hard2
69 " \
70 "" ""
71
72 optional FEATURE_TAR_LONG_OPTIONS
73 testing "tar --overwrite" "\
74 rm -rf input_* test.tar 2>/dev/null
75 ln input input_hard
76 tar cf test.tar input_hard
77 echo WRONG >input
78 # --overwrite opens 'input_hard' without unlinking,
79 # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
80 tar xf test.tar --overwrite 2>&1 && cat input
81 " "\
82 Ok
83 " \
84 "Ok\n" ""
85 SKIP=
86
87 cd .. && rm -rf tar.tempdir || exit 1
88
89 exit $FAILCOUNT