blob: 472064f7f1a259818e4b9065501cdca22790376b [file] [log] [blame]
Denys Vlasenkobf224752009-11-29 19:09:29 +01001#!/bin/sh
2# Copyright 2009 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denys Vlasenkobf224752009-11-29 19:09:29 +01004
5. ./testing.sh
6
Dan Fandrich775965d2010-08-10 23:33:57 -07007unset LANG
8unset LANGUAGE
9unset LC_COLLATE
10unset LC_ALL
11umask 022
12
Denys Vlasenko02365a62010-04-09 10:52:52 +020013rm -rf tar.tempdir 2>/dev/null
14mkdir tar.tempdir && cd tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +010015
16# testing "test name" "script" "expected result" "file input" "stdin"
17
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020018optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020019testing "tar hardlinks and repeated files" '\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010020rm -rf input_* test.tar 2>/dev/null
21>input_hard1
Denys Vlasenkobf224752009-11-29 19:09:29 +010022ln input_hard1 input_hard2
23mkdir input_dir
24>input_dir/file
Denys Vlasenko02365a62010-04-09 10:52:52 +020025chmod -R 644 *
26chmod 755 input_dir
Denys Vlasenkobf224752009-11-29 19:09:29 +010027tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
Denys Vlasenko02365a62010-04-09 10:52:52 +020028tar 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' "\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010033input
Denys Vlasenkobf224752009-11-29 19:09:29 +010034input_dir/
35input_dir/file
36input_hard1
37input_hard2 -> input_hard1
38input_hard1 -> input_hard1
39input_dir/
40input_dir/file
41input
Denys Vlasenko02365a62010-04-09 10:52:52 +020042Ok: 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"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020049SKIP=
Denys Vlasenko02365a62010-04-09 10:52:52 +020050
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020051optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020052testing "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
Denys Vlasenko02365a62010-04-09 10:52:52 +020058ln input_hard1 input_dir
59ln input_hard2 input_dir
Dan Fandricheb2bf5b2010-09-02 18:38:00 -070060chmod 550 input_dir
Denys Vlasenko0d7cb4c2010-09-03 17:22:56 +020061# 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*
Denys Vlasenko02365a62010-04-09 10:52:52 +020064tar tvf test.tar | sed "s/.*[0-9] input/input/"
Dan Fandricheb2bf5b2010-09-02 18:38:00 -070065chmod 770 input_dir
66rm -rf input_*
Denys Vlasenko02365a62010-04-09 10:52:52 +020067tar xf test.tar 2>&1
68echo Ok: $?
Denys Vlasenko0d7cb4c2010-09-03 17:22:56 +020069ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
Denys Vlasenko02365a62010-04-09 10:52:52 +020070' "\
Denys Vlasenko02365a62010-04-09 10:52:52 +020071input_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
Denys Vlasenko02365a62010-04-09 10:52:52 +020078-rwxr----x input_hard1
79-rwxr----x input_hard2
Denys Vlasenkobf224752009-11-29 19:09:29 +010080" \
81"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020082SKIP=
Denys Vlasenkobf224752009-11-29 19:09:29 +010083
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020084optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020085testing "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
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020091ln input_file input_dir
92ln input_soft input_dir
Dan Fandricheb2bf5b2010-09-02 18:38:00 -070093chmod 550 input_dir
Dan Fandrich80d80ba2010-09-11 00:28:50 -070094tar cf test.tar input_dir/* input_[fs]*
Denys Vlasenkoe82cf332010-05-12 15:59:32 +020095tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
Dan Fandricheb2bf5b2010-09-02 18:38:00 -070096chmod 770 input_dir
97rm -rf input_*
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020098tar xf test.tar 2>&1
99echo Ok: $?
Dan Fandrich80d80ba2010-09-11 00:28:50 -0700100ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200101' "\
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200102input_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
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200109-rwxr----x input_file
110lrwxrwxrwx input_file
111" \
112"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200113SKIP=
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200114
Denys Vlasenkoda138242010-05-11 12:02:48 +0200115optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100116testing "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" ""
Chris Metcalf208d35d2010-04-02 09:57:27 +0200128SKIP=
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100129
Dan Fandrich80d80ba2010-09-11 00:28:50 -0700130test x"$SKIP_KNOWN_BUGS" = x"" && {
Dan Fandrich8d789e42010-09-05 16:16:46 +0200131# 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=
Dan Fandrich80d80ba2010-09-11 00:28:50 -0700155}
156
Denys Vlasenkob8ab4b02011-02-06 20:02:15 +0100157# Had a bug where on extract autodetect first "switched off" -z
Denys Vlasenkoaef441c2011-02-06 20:01:11 +0100158# and then failed to recognize .tgz extension
159testing "tar extract tgz" "\
160dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
161tar -czf F0.tgz F0
162rm F0
163tar -xzvf F0.tgz && echo Ok
164rm F0 || echo BAD
165" "\
166F0
167Ok
168" \
169"" ""
170
Dan Fandrich8d789e42010-09-05 16:16:46 +0200171
Denys Vlasenko02365a62010-04-09 10:52:52 +0200172cd .. && rm -rf tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +0100173
174exit $FAILCOUNT