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 | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 18 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 19 | testing "tar hardlinks and repeated files" '\ |
Denys Vlasenko | 425ad9c | 2009-12-16 22:46:01 +0100 | [diff] [blame] | 20 | rm -rf input_* test.tar 2>/dev/null |
| 21 | >input_hard1 |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 22 | ln input_hard1 input_hard2 |
| 23 | mkdir input_dir |
| 24 | >input_dir/file |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 25 | chmod -R 644 * |
| 26 | chmod 755 input_dir |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 27 | 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] | 28 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
| 29 | tar xf test.tar 2>&1 |
| 30 | echo Ok: $? |
| 31 | ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
| 32 | ' "\ |
Denys Vlasenko | 425ad9c | 2009-12-16 22:46:01 +0100 | [diff] [blame] | 33 | input |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 34 | input_dir/ |
| 35 | input_dir/file |
| 36 | input_hard1 |
| 37 | input_hard2 -> input_hard1 |
| 38 | input_hard1 -> input_hard1 |
| 39 | input_dir/ |
| 40 | input_dir/file |
| 41 | input |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 42 | Ok: 0 |
| 43 | -rw-r--r-- input_dir/file |
| 44 | drwxr-xr-x input_dir |
| 45 | -rw-r--r-- input_hard1 |
| 46 | -rw-r--r-- input_hard2 |
| 47 | " \ |
| 48 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 49 | SKIP= |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 50 | |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 51 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 52 | testing "tar hardlinks mode" '\ |
| 53 | rm -rf input_* test.tar 2>/dev/null |
| 54 | >input_hard1 |
| 55 | chmod 741 input_hard1 |
| 56 | ln input_hard1 input_hard2 |
| 57 | mkdir input_dir |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 58 | ln input_hard1 input_dir |
| 59 | ln input_hard2 input_dir |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 60 | chmod 550 input_dir |
Denys Vlasenko | 0d7cb4c | 2010-09-03 17:22:56 +0200 | [diff] [blame] | 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_*": |
| 63 | tar cf test.tar input_dir/input_hard* input_hard* |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 64 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 65 | chmod 770 input_dir |
| 66 | rm -rf input_* |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 67 | tar xf test.tar 2>&1 |
| 68 | echo Ok: $? |
Denys Vlasenko | 0d7cb4c | 2010-09-03 17:22:56 +0200 | [diff] [blame] | 69 | ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 70 | ' "\ |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 71 | input_dir/input_hard1 |
| 72 | input_dir/input_hard2 -> input_dir/input_hard1 |
| 73 | input_hard1 -> input_dir/input_hard1 |
| 74 | input_hard2 -> input_dir/input_hard1 |
| 75 | Ok: 0 |
| 76 | -rwxr----x input_dir/input_hard1 |
| 77 | -rwxr----x input_dir/input_hard2 |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 78 | -rwxr----x input_hard1 |
| 79 | -rwxr----x input_hard2 |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 80 | " \ |
| 81 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 82 | SKIP= |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 83 | |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 84 | optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 85 | testing "tar symlinks mode" '\ |
| 86 | rm -rf input_* test.tar 2>/dev/null |
| 87 | >input_file |
| 88 | chmod 741 input_file |
| 89 | ln -s input_file input_soft |
| 90 | mkdir input_dir |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 91 | ln input_file input_dir |
| 92 | ln input_soft input_dir |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 93 | chmod 550 input_dir |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 94 | tar cf test.tar input_* |
Denys Vlasenko | e82cf33 | 2010-05-12 15:59:32 +0200 | [diff] [blame] | 95 | tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort |
Dan Fandrich | eb2bf5b | 2010-09-02 18:38:00 -0700 | [diff] [blame] | 96 | chmod 770 input_dir |
| 97 | rm -rf input_* |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 98 | tar xf test.tar 2>&1 |
| 99 | echo Ok: $? |
| 100 | ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
| 101 | ' "\ |
| 102 | input_dir/ |
| 103 | input_dir/input_file |
| 104 | input_dir/input_soft -> input_file |
| 105 | input_file -> input_dir/input_file |
| 106 | input_soft -> input_dir/input_soft |
| 107 | Ok: 0 |
| 108 | -rwxr----x input_dir/input_file |
| 109 | lrwxrwxrwx input_file |
| 110 | dr-xr-x--- input_dir |
| 111 | -rwxr----x input_file |
| 112 | lrwxrwxrwx input_file |
| 113 | " \ |
| 114 | "" "" |
Denys Vlasenko | e3d90a9 | 2010-05-10 05:53:16 +0200 | [diff] [blame] | 115 | SKIP= |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 116 | |
Denys Vlasenko | da13824 | 2010-05-11 12:02:48 +0200 | [diff] [blame] | 117 | optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS |
Denys Vlasenko | 8a936cf | 2009-12-16 23:18:59 +0100 | [diff] [blame] | 118 | testing "tar --overwrite" "\ |
| 119 | rm -rf input_* test.tar 2>/dev/null |
| 120 | ln input input_hard |
| 121 | tar cf test.tar input_hard |
| 122 | echo WRONG >input |
| 123 | # --overwrite opens 'input_hard' without unlinking, |
| 124 | # thus 'input_hard' still linked to 'input' and we write 'Ok' into it |
| 125 | tar xf test.tar --overwrite 2>&1 && cat input |
| 126 | " "\ |
| 127 | Ok |
| 128 | " \ |
| 129 | "Ok\n" "" |
Chris Metcalf | 208d35d | 2010-04-02 09:57:27 +0200 | [diff] [blame] | 130 | SKIP= |
Denys Vlasenko | 8a936cf | 2009-12-16 23:18:59 +0100 | [diff] [blame] | 131 | |
Dan Fandrich | 8d789e4 | 2010-09-05 16:16:46 +0200 | [diff] [blame] | 132 | # Needs to be run under non-root for meaningful test |
| 133 | optional FEATURE_TAR_CREATE |
| 134 | testing "tar writing into read-only dir" '\ |
| 135 | rm -rf input_* test.tar 2>/dev/null |
| 136 | mkdir input_dir |
| 137 | >input_dir/input_file |
| 138 | chmod 550 input_dir |
| 139 | tar cf test.tar input_dir |
| 140 | tar tvf test.tar | sed "s/.*[0-9] input/input/" |
| 141 | chmod 770 input_dir |
| 142 | rm -rf input_* |
| 143 | tar xf test.tar 2>&1 |
| 144 | echo Ok: $? |
| 145 | ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/" |
| 146 | chmod 770 input_dir |
| 147 | ' "\ |
| 148 | input_dir/ |
| 149 | input_dir/input_file |
| 150 | Ok: 0 |
| 151 | -rw-r--r-- input_dir/input_file |
| 152 | dr-xr-x--- input_dir |
| 153 | " \ |
| 154 | "" "" |
| 155 | SKIP= |
| 156 | |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 157 | cd .. && rm -rf tar.tempdir || exit 1 |
Denys Vlasenko | bf22475 | 2009-11-29 19:09:29 +0100 | [diff] [blame] | 158 | |
| 159 | exit $FAILCOUNT |