| 1 |
# Process this file with autom4te to create testsuite. -*- Autotest -*- |
| 2 |
# |
| 3 |
# Test suite for GNU tar. |
| 4 |
# Copyright 2017-2023 Free Software Foundation, Inc. |
| 5 |
|
| 6 |
# This file is part of GNU tar. |
| 7 |
|
| 8 |
# GNU tar is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
|
| 13 |
# GNU tar is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
|
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
AT_SETUP([keep-directory-symlink]) |
| 22 |
AT_KEYWORDS([extrac20 extract old-files keep-old-files]) |
| 23 |
|
| 24 |
AT_TAR_CHECK([ |
| 25 |
AT_SORT_PREREQ |
| 26 |
|
| 27 |
for i in a b c |
| 28 |
do |
| 29 |
dir=in$i |
| 30 |
mkdir -p $dir/root/dir $dir/root/dirsymlink |
| 31 |
touch $dir/root/dirsymlink/file$i |
| 32 |
test $i != a && touch $dir/root/dirsymlink/file.conflict |
| 33 |
tar cf archive$i.tar -C $dir root |
| 34 |
done |
| 35 |
|
| 36 |
prep() |
| 37 |
{ |
| 38 |
echo "== $1 ==" |
| 39 |
echo "== $1 ==" >&2 |
| 40 |
backup_dir=$1 |
| 41 |
dir=out |
| 42 |
mkdir -p $dir/root/dir |
| 43 |
ln -s dir $dir/root/dirsymlink |
| 44 |
test $round = normal && cd $dir >/dev/null |
| 45 |
} |
| 46 |
|
| 47 |
clean() |
| 48 |
{ |
| 49 |
test $round = normal && cd .. >/dev/null |
| 50 |
find $dir | sort |
| 51 |
mv $dir $backup_dir |
| 52 |
} |
| 53 |
|
| 54 |
# Expand to '-f ../$1' or '-f $1 -C $dir' depending on $round variable |
| 55 |
file_spec() |
| 56 |
{ |
| 57 |
if test $round = normal |
| 58 |
then |
| 59 |
echo "-f ../$1" |
| 60 |
else |
| 61 |
echo "-f $1 -C $dir" |
| 62 |
fi |
| 63 |
} |
| 64 |
|
| 65 |
for round in normal dir |
| 66 |
do |
| 67 |
# Check that 'dirsymlink' replaces 'dir' |
| 68 |
prep without_option_$round |
| 69 |
tar -x `file_spec archivea.tar` || exit 1 |
| 70 |
tar -x `file_spec archiveb.tar` || exit 1 |
| 71 |
clean |
| 72 |
|
| 73 |
# Keep directory symlink must keep root/dirsymlink |
| 74 |
prep with_option_$round |
| 75 |
tar -x --keep-directory-symlink `file_spec archivea.tar` || exit 1 |
| 76 |
tar -x --keep-directory-symlink `file_spec archiveb.tar` || exit 1 |
| 77 |
clean |
| 78 |
|
| 79 |
prep collision_$round |
| 80 |
tar -x --keep-directory-symlink `file_spec archivea.tar` --keep-old-files || exit 1 |
| 81 |
tar -x --keep-directory-symlink `file_spec archiveb.tar` --keep-old-files || exit 1 |
| 82 |
tar -x --keep-directory-symlink `file_spec archivec.tar` --keep-old-files && exit 1 |
| 83 |
clean |
| 84 |
done |
| 85 |
], |
| 86 |
[0], |
| 87 |
[== without_option_normal == |
| 88 |
out |
| 89 |
out/root |
| 90 |
out/root/dir |
| 91 |
out/root/dirsymlink |
| 92 |
out/root/dirsymlink/file.conflict |
| 93 |
out/root/dirsymlink/filea |
| 94 |
out/root/dirsymlink/fileb |
| 95 |
== with_option_normal == |
| 96 |
out |
| 97 |
out/root |
| 98 |
out/root/dir |
| 99 |
out/root/dir/file.conflict |
| 100 |
out/root/dir/filea |
| 101 |
out/root/dir/fileb |
| 102 |
out/root/dirsymlink |
| 103 |
== collision_normal == |
| 104 |
out |
| 105 |
out/root |
| 106 |
out/root/dir |
| 107 |
out/root/dir/file.conflict |
| 108 |
out/root/dir/filea |
| 109 |
out/root/dir/fileb |
| 110 |
out/root/dir/filec |
| 111 |
out/root/dirsymlink |
| 112 |
== without_option_dir == |
| 113 |
out |
| 114 |
out/root |
| 115 |
out/root/dir |
| 116 |
out/root/dirsymlink |
| 117 |
out/root/dirsymlink/file.conflict |
| 118 |
out/root/dirsymlink/filea |
| 119 |
out/root/dirsymlink/fileb |
| 120 |
== with_option_dir == |
| 121 |
out |
| 122 |
out/root |
| 123 |
out/root/dir |
| 124 |
out/root/dir/file.conflict |
| 125 |
out/root/dir/filea |
| 126 |
out/root/dir/fileb |
| 127 |
out/root/dirsymlink |
| 128 |
== collision_dir == |
| 129 |
out |
| 130 |
out/root |
| 131 |
out/root/dir |
| 132 |
out/root/dir/file.conflict |
| 133 |
out/root/dir/filea |
| 134 |
out/root/dir/fileb |
| 135 |
out/root/dir/filec |
| 136 |
out/root/dirsymlink |
| 137 |
], |
| 138 |
[== without_option_normal == |
| 139 |
== with_option_normal == |
| 140 |
== collision_normal == |
| 141 |
tar: root/dirsymlink/file.conflict: Cannot open: File exists |
| 142 |
tar: Exiting with failure status due to previous errors |
| 143 |
== without_option_dir == |
| 144 |
== with_option_dir == |
| 145 |
== collision_dir == |
| 146 |
tar: root/dirsymlink/file.conflict: Cannot open: File exists |
| 147 |
tar: Exiting with failure status due to previous errors |
| 148 |
]) |
| 149 |
|
| 150 |
AT_CLEANUP |
| 151 |
|