blob: f4007903776d67132387ceda583b5860c983f1c8 [file] [log] [blame]
Denys Vlasenkobf224752009-11-29 19:09:29 +01001#!/bin/sh
2# Copyright 2009 by Denys Vlasenko
3# Licensed under GPL v2, see file LICENSE for details.
4
5. ./testing.sh
6
Denys Vlasenko02365a62010-04-09 10:52:52 +02007rm -rf tar.tempdir 2>/dev/null
8mkdir tar.tempdir && cd tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +01009
10# testing "test name" "script" "expected result" "file input" "stdin"
11
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020012optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020013testing "tar hardlinks and repeated files" '\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010014rm -rf input_* test.tar 2>/dev/null
15>input_hard1
Denys Vlasenkobf224752009-11-29 19:09:29 +010016ln input_hard1 input_hard2
17mkdir input_dir
18>input_dir/file
Denys Vlasenko02365a62010-04-09 10:52:52 +020019chmod -R 644 *
20chmod 755 input_dir
Denys Vlasenkobf224752009-11-29 19:09:29 +010021tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
Denys Vlasenko02365a62010-04-09 10:52:52 +020022tar tvf test.tar | sed "s/.*[0-9] input/input/"
23tar xf test.tar 2>&1
24echo Ok: $?
25ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
26' "\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010027input
Denys Vlasenkobf224752009-11-29 19:09:29 +010028input_dir/
29input_dir/file
30input_hard1
31input_hard2 -> input_hard1
32input_hard1 -> input_hard1
33input_dir/
34input_dir/file
35input
Denys Vlasenko02365a62010-04-09 10:52:52 +020036Ok: 0
37-rw-r--r-- input_dir/file
38drwxr-xr-x input_dir
39-rw-r--r-- input_hard1
40-rw-r--r-- input_hard2
41" \
42"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020043SKIP=
Denys Vlasenko02365a62010-04-09 10:52:52 +020044
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020045optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020046testing "tar hardlinks mode" '\
47rm -rf input_* test.tar 2>/dev/null
48>input_hard1
49chmod 741 input_hard1
50ln input_hard1 input_hard2
51mkdir input_dir
52chmod 550 input_dir
53ln input_hard1 input_dir
54ln input_hard2 input_dir
55tar cf test.tar input_*
56tar tvf test.tar | sed "s/.*[0-9] input/input/"
57tar xf test.tar 2>&1
58echo Ok: $?
59ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
60' "\
61input_dir/
62input_dir/input_hard1
63input_dir/input_hard2 -> input_dir/input_hard1
64input_hard1 -> input_dir/input_hard1
65input_hard2 -> input_dir/input_hard1
66Ok: 0
67-rwxr----x input_dir/input_hard1
68-rwxr----x input_dir/input_hard2
69dr-xr-x--- input_dir
70-rwxr----x input_hard1
71-rwxr----x input_hard2
Denys Vlasenkobf224752009-11-29 19:09:29 +010072" \
73"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020074SKIP=
Denys Vlasenkobf224752009-11-29 19:09:29 +010075
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020076optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020077testing "tar symlinks mode" '\
78rm -rf input_* test.tar 2>/dev/null
79>input_file
80chmod 741 input_file
81ln -s input_file input_soft
82mkdir input_dir
83chmod 550 input_dir
84ln input_file input_dir
85ln input_soft input_dir
86tar cf test.tar input_*
Denys Vlasenkoe82cf332010-05-12 15:59:32 +020087tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020088tar xf test.tar 2>&1
89echo Ok: $?
90ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
91' "\
92input_dir/
93input_dir/input_file
94input_dir/input_soft -> input_file
95input_file -> input_dir/input_file
96input_soft -> input_dir/input_soft
97Ok: 0
98-rwxr----x input_dir/input_file
99lrwxrwxrwx input_file
100dr-xr-x--- input_dir
101-rwxr----x input_file
102lrwxrwxrwx input_file
103" \
104"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200105SKIP=
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200106
Denys Vlasenkoda138242010-05-11 12:02:48 +0200107optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100108testing "tar --overwrite" "\
109rm -rf input_* test.tar 2>/dev/null
110ln input input_hard
111tar cf test.tar input_hard
112echo WRONG >input
113# --overwrite opens 'input_hard' without unlinking,
114# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
115tar xf test.tar --overwrite 2>&1 && cat input
116" "\
117Ok
118" \
119"Ok\n" ""
Chris Metcalf208d35d2010-04-02 09:57:27 +0200120SKIP=
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100121
Denys Vlasenko02365a62010-04-09 10:52:52 +0200122cd .. && rm -rf tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +0100123
124exit $FAILCOUNT