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