blob: dd502c23df188746f826bef67057cf2ff64d8da1 [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
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020094tar cf test.tar input_*
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: $?
100ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
101' "\
102input_dir/
103input_dir/input_file
104input_dir/input_soft -> input_file
105input_file -> input_dir/input_file
106input_soft -> input_dir/input_soft
107Ok: 0
108-rwxr----x input_dir/input_file
109lrwxrwxrwx input_file
110dr-xr-x--- input_dir
111-rwxr----x input_file
112lrwxrwxrwx input_file
113" \
114"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200115SKIP=
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200116
Denys Vlasenkoda138242010-05-11 12:02:48 +0200117optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100118testing "tar --overwrite" "\
119rm -rf input_* test.tar 2>/dev/null
120ln input input_hard
121tar cf test.tar input_hard
122echo WRONG >input
123# --overwrite opens 'input_hard' without unlinking,
124# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
125tar xf test.tar --overwrite 2>&1 && cat input
126" "\
127Ok
128" \
129"Ok\n" ""
Chris Metcalf208d35d2010-04-02 09:57:27 +0200130SKIP=
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100131
Dan Fandrich8d789e42010-09-05 16:16:46 +0200132# Needs to be run under non-root for meaningful test
133optional FEATURE_TAR_CREATE
134testing "tar writing into read-only dir" '\
135rm -rf input_* test.tar 2>/dev/null
136mkdir input_dir
137>input_dir/input_file
138chmod 550 input_dir
139tar cf test.tar input_dir
140tar tvf test.tar | sed "s/.*[0-9] input/input/"
141chmod 770 input_dir
142rm -rf input_*
143tar xf test.tar 2>&1
144echo Ok: $?
145ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
146chmod 770 input_dir
147' "\
148input_dir/
149input_dir/input_file
150Ok: 0
151-rw-r--r-- input_dir/input_file
152dr-xr-x--- input_dir
153" \
154"" ""
155SKIP=
156
Denys Vlasenko02365a62010-04-09 10:52:52 +0200157cd .. && rm -rf tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +0100158
159exit $FAILCOUNT