| 1 |
#!/bin/sh |
| 2 |
# - test that cabextract doesn't follow symlinks when extracting files |
| 3 |
# (default behaviour) but does when given the -k option |
| 4 |
# - also check that it doesn't delete symlinks in the path supplied by the |
| 5 |
# user (-d option) |
| 6 |
# - also check that the -n option stops overwriting files |
| 7 |
. test/testcase |
| 8 |
|
| 9 |
set -e # every command is a test! |
| 10 |
|
| 11 |
# set up a symlinked file and symlinked directory |
| 12 |
# extract $tmpdir/plain.c and $tmpdir/1/2/3/4.c |
| 13 |
# check they did NOT get written to $tmpdir/other.c and $tmpdir/other/4.c |
| 14 |
touch $tmpdir/other.c |
| 15 |
mkdir $tmpdir/1 $tmpdir/1/2 $tmpdir/other |
| 16 |
ln -s $tmpdir/other.c $tmpdir/plain.c |
| 17 |
ln -s $tmpdir/other $tmpdir/1/2/3 |
| 18 |
"$cabextract" -q -d $tmpdir cabs/dir.cab |
| 19 |
[ -s $tmpdir/plain.c -a \! -s $tmpdir/other.c ] |
| 20 |
[ -s $tmpdir/1/2/3/4.c -a \! -s $tmpdir/other/4.c ] |
| 21 |
|
| 22 |
# restore the symlinked file/dir |
| 23 |
# extract again with -k option |
| 24 |
# check they DID get written to $tmpdir/other.c and $tmpdir/other/3/4.c |
| 25 |
rm -rf $tmpdir/1/2/3 $tmpdir/plain.c |
| 26 |
ln -s $tmpdir/other.c $tmpdir/plain.c |
| 27 |
ln -s $tmpdir/other $tmpdir/1/2/3 |
| 28 |
"$cabextract" -q -k -d $tmpdir cabs/dir.cab |
| 29 |
[ -s $tmpdir/other.c -a -h $tmpdir/plain.c ] |
| 30 |
[ -s $tmpdir/other/4.c -a -h $tmpdir/1/2/3 ] |
| 31 |
|
| 32 |
# extract to a user-selected directory path that has symlinks in it. |
| 33 |
# check that those symlinks are preserved, but symlinks in the parts |
| 34 |
# of the path that are archive-controlled are removed |
| 35 |
rm -rf $tmpdir/1 $tmpdir/other/4.c $tmpdir/other.c $tmpdir/plain.c |
| 36 |
find $tmpdir -ls |
| 37 |
touch $tmpdir/other.c |
| 38 |
mkdir $tmpdir/real |
| 39 |
ln -s $tmpdir/real $tmpdir/fake |
| 40 |
mkdir $tmpdir/fake/dest $tmpdir/fake/dest/1 $tmpdir/fake/dest/1/2 |
| 41 |
ln -s $tmpdir/other $tmpdir/fake/dest/1/2/3 |
| 42 |
ln -s $tmpdir/other.c $tmpdir/plain.c |
| 43 |
"$cabextract" -q -d $tmpdir/fake/dest cabs/dir.cab |
| 44 |
[ -s $tmpdir/fake/dest/plain.c -a \! -s $tmpdir/other.c ] |
| 45 |
[ -s $tmpdir/fake/dest/1/2/3/4.c -a \! -s $tmpdir/other/3/4.c ] |
| 46 |
[ -h $tmpdir/fake -a -d $tmpdir/fake/dest ] |
| 47 |
|
| 48 |
# check that -n option works |
| 49 |
echo hello > $tmpdir/fake/dest/plain.c |
| 50 |
echo world > $tmpdir/fake/dest/1/2/3/4.c |
| 51 |
"$cabextract" -q -n -d $tmpdir/fake/dest cabs/dir.cab |
| 52 |
read H < $tmpdir/fake/dest/plain.c |
| 53 |
read W < $tmpdir/fake/dest/1/2/3/4.c |
| 54 |
[ "$H" = "hello" -a "$W" = "world" ] |
| 55 |
|
| 56 |
exit 0 |