X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/8d48388ebfb69ab21a50d068275d2f6b7abffb87..de6a3945e1211f6edf2069e11f6fbe522d6776d5:/test/test-indexes.sh

diff --git a/test/test-indexes.sh b/test/test-indexes.sh
index 58b9cff72..50d54f691 100755
--- a/test/test-indexes.sh
+++ b/test/test-indexes.sh
@@ -15,19 +15,107 @@ TEST_PKG="python-psyco-doc"
 
 export LD_LIBRARY_PATH=$BUILDDIR/bin
 
-OPTS="-o RootDir=. -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
+OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
 DEBUG=""
 #DEBUG="-o Debug::pkgCacheGen=true"
 #DEBUG="-o Debug::pkgAcquire=true"
 APT_GET="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
 APT_CACHE="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"
+APT_FTPARCHIVE="$BUILDDIR/bin/apt-ftparchive"
 
 [ -x "$BUILDDIR/bin/apt-get" ] || {
     echo "please build the tree first" >&2
     exit 1
 }
 
-echo "---- building sandbox----"
+check_update() {
+    echo "--- apt-get update $@ (no trusted keys)"
+
+    rm -f etc/apt/trusted.gpg etc/apt/secring.gpg
+    touch etc/apt/trusted.gpg etc/apt/secring.gpg
+    find var/lib/apt/lists/ -type f | xargs -r rm
+
+    # first attempt should fail, no trusted GPG key
+    out=$($APT_GET "$@" update 2>&1)
+    echo "$out" | grep -q NO_PUBKEY
+    key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
+
+    # get keyring
+    gpg -q --no-options --no-default-keyring --secret-keyring etc/apt/secring.gpg --trustdb-name etc/apt/trustdb.gpg --keyring etc/apt/trusted.gpg --primary-keyring etc/apt/trusted.gpg --keyserver $GPG_KEYSERVER --recv-keys $key
+
+    # now it should work
+    echo "--- apt-get update $@ (with trusted keys)"
+    find var/lib/apt/lists/ -type f | xargs -r rm
+    $APT_GET "$@" update
+}
+
+# if $1 == "compressed", check that we have compressed indexes, otherwise
+# uncompressed ones
+check_indexes() {
+    echo "--- only ${1:-uncompressed} index files present"
+    local F
+    if [ "$1" = "compressed" ]; then
+	! test -e var/lib/apt/lists/*_Packages || F=1
+	! test -e var/lib/apt/lists/*_Sources || F=1
+	test -e var/lib/apt/lists/*_Packages.gz || F=1
+	test -e var/lib/apt/lists/*_Sources.gz || F=1
+    else
+	test -e var/lib/apt/lists/*_Packages || F=1
+	test -e var/lib/apt/lists/*_Sources || F=1
+	! test -e var/lib/apt/lists/*_Packages.gz || F=1
+	! test -e var/lib/apt/lists/*_Sources.gz || F=1
+    fi
+
+    if [ -n "$F" ]; then
+	ls -laR var/lib/apt/lists/
+	exit 1
+    fi
+}
+
+# test apt-cache commands
+check_cache() {
+    echo "--- apt-cache commands"
+
+    $APT_CACHE show $TEST_PKG | grep -q ^Version:
+    # again (with cache)
+    $APT_CACHE show $TEST_PKG | grep -q ^Version:
+    rm var/cache/apt/*.bin
+    $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
+    # again (with cache)
+    $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
+
+    TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
+    rm var/cache/apt/*.bin
+    $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
+    # again (with cache)
+    $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
+}
+
+# test apt-get install
+check_install() {
+    echo "--- apt-get install"
+
+    $APT_GET install -d $TEST_PKG 
+    test -e var/cache/apt/archives/$TEST_PKG*.deb
+    $APT_GET clean
+    ! test -e var/cache/apt/archives/$TEST_PKG*.deb
+}
+
+# test apt-get source
+check_get_source() {
+    echo "--- apt-get source"
+    # quiesce: it'll complain about not being able to verify the signature
+    $APT_GET source $TEST_PKG >/dev/null 2>&1
+    test -f $TEST_SRC_*.dsc
+    test -d $TEST_SRC-*
+    rm -r $TEST_SRC*
+}
+
+############################################################################
+# main
+############################################################################
+
+echo "===== building sandbox ====="
 WORKDIR=$(mktemp -d)
 trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 cd $WORKDIR
@@ -35,112 +123,113 @@ cd $WORKDIR
 rm -fr etc var
 rm -f home
 ln -s /home home
-mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
+mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d etc/apt/apt.conf.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
 cp /etc/apt/trusted.gpg etc/apt
 touch var/lib/dpkg/status
 echo "deb $TEST_SOURCE" > etc/apt/sources.list
 echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
 
-echo "---- uncompressed update ----"
-# first attempt should fail, no trusted GPG key
-out=$($APT_GET update 2>&1)
-echo "$out" | grep -q NO_PUBKEY
-key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
-# get keyring
-gpg --no-options --no-default-keyring --secret-keyring etc/apt/secring.gpg --trustdb-name etc/apt/trustdb.gpg --keyring etc/apt/trusted.gpg --primary-keyring etc/apt/trusted.gpg --keyserver $GPG_KEYSERVER --recv-keys $key
+# specifying -o RootDir at the command line does not work for
+# etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
+# checked first, so this works
+echo "RootDir \"$WORKDIR\";" > apt_config
+export APT_CONFIG=`pwd`/apt_config
+
+echo "==== no indexes ===="
+echo '--- apt-get check works without indexes'
+[ -z `$APT_GET check` ]
+echo '--- apt-cache policy works without indexes'
+$APT_CACHE policy bash >/dev/null
+echo '--- apt-cache show works without indexes'
+! LC_MESSAGES=C $APT_CACHE show bash 2>&1| grep -q 'E: No packages found'
+
+echo "===== uncompressed indexes ====="
+echo 'Acquire::GzipIndexes "false";' > etc/apt/apt.conf.d/02compress-indexes
+check_update
+check_indexes
+check_cache
+check_install
+check_get_source
+
+echo "--- apt-get update with preexisting indexes"
 $APT_GET update
+check_indexes
+check_cache
 
-test -e var/lib/apt/lists/*_Packages
-test -e var/lib/apt/lists/*_Sources
-! test -e var/lib/apt/lists/*_Packages.gz
-! test -e var/lib/apt/lists/*_Sources.gz
-
-echo "---- uncompressed cache ----"
-$APT_CACHE show $TEST_PKG | grep -q ^Version:
-# again (with cache)
-$APT_CACHE show $TEST_PKG | grep -q ^Version:
-rm var/cache/apt/*.bin
-$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
-# again (with cache)
-$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
-
-TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
-rm var/cache/apt/*.bin
-$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
-# again (with cache)
-$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
-
-echo "---- uncompressed install ----"
-$APT_GET install -d $TEST_PKG 
-test -e var/cache/apt/archives/$TEST_PKG*.deb
-$APT_GET clean
-! test -e var/cache/apt/archives/$TEST_PKG*.deb
-
-echo "---- uncompressed get source ----"
-$APT_GET source $TEST_PKG
-test -f $TEST_SRC_*.dsc
-test -d $TEST_SRC-*
-rm -r $TEST_SRC*
-
-echo "----- uncompressed update with preexisting indexes, no pdiff ----"
-$APT_GET -o Acquire::PDiffs=false update
-test -e var/lib/apt/lists/*_Packages
-test -e var/lib/apt/lists/*_Sources
-! test -e var/lib/apt/lists/*_Packages.gz
-! test -e var/lib/apt/lists/*_Sources.gz
-
-echo "----- uncompressed update with preexisting indexes, with pdiff ----"
+echo "--- apt-get update with preexisting indexes and pdiff mode"
 $APT_GET -o Acquire::PDiffs=true update
-test -e var/lib/apt/lists/*_Packages
-test -e var/lib/apt/lists/*_Sources
-! test -e var/lib/apt/lists/*_Packages.gz
-! test -e var/lib/apt/lists/*_Sources.gz
+check_indexes
+check_cache
+
+echo "===== compressed indexes (CLI option) ====="
+check_update -o Acquire::GzipIndexes=true
+check_indexes compressed
+check_cache
+check_install
+check_get_source
 
-echo "----- compressed update ----"
-find var/lib/apt/lists/ -type f | xargs -r rm
+echo "--- apt-get update with preexisting indexes"
 $APT_GET -o Acquire::GzipIndexes=true update
-! test -e var/lib/apt/lists/*_Packages
-! test -e var/lib/apt/lists/*_Sources
-test -e var/lib/apt/lists/*_Packages.gz
-test -e var/lib/apt/lists/*_Sources.gz
-
-echo "---- compressed cache ----"
-$APT_CACHE show $TEST_PKG | grep -q ^Version:
-# again (with cache)
-$APT_CACHE show $TEST_PKG | grep -q ^Version:
-rm var/cache/apt/*.bin
-$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
-# again (with cache)
-$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
-
-TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
-rm var/cache/apt/*.bin
-$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
-# again (with cache)
-$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
-
-echo "---- compressed install ----"
+check_indexes compressed
+check_cache
+
+echo "--- apt-get update with preexisting indexes and pdiff mode"
+$APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
+check_indexes compressed
+check_cache
+
+echo "===== compressed indexes (apt.conf.d option) ====="
+cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
+Acquire::GzipIndexes "true";
+Acquire::CompressionTypes::Order:: "gz";
+EOF
+
+check_update
+check_indexes compressed
+check_cache
+check_install
+check_get_source
+
+echo "--- apt-get update with preexisting indexes"
+$APT_GET update
+check_indexes compressed
+check_cache
+
+echo "--- apt-get update with preexisting indexes and pdiff mode"
+$APT_GET -o Acquire::PDiffs=true update
+check_indexes compressed
+check_cache
+
+rm etc/apt/apt.conf.d/02compress-indexes
+
+echo "==== apt-ftparchive ===="
+mkdir arch
 $APT_GET install -d $TEST_PKG 
-! test -e var/cache/apt/archives/$TEST_PKG*.deb
-
-echo "---- compressed get source ----"
-$APT_GET source $TEST_PKG
-test -f $TEST_SRC_*.dsc
-test -d $TEST_SRC-*
-rm -r $TEST_SRC*
-
-echo "----- compressed update with preexisting indexes, no pdiff ----"
-$APT_GET -o Acquire::PDiffs=false -o Acquire::GzipIndexes=true update
-! test -e var/lib/apt/lists/*_Packages
-! test -e var/lib/apt/lists/*_Sources
-test -e var/lib/apt/lists/*_Packages.gz
-test -e var/lib/apt/lists/*_Sources.gz
-
-echo "----- compressed update with preexisting indexes, with pdiff ----"
-$APT_GET -o Acquire::PDiffs=true -o Acquire::GzipIndexes=true update
-! test -e var/lib/apt/lists/*_Packages
-! test -e var/lib/apt/lists/*_Sources
-test -e var/lib/apt/lists/*_Packages.gz
-test -e var/lib/apt/lists/*_Sources.gz
-
-echo "---- ALL TESTS PASSED ----"
+cp var/cache/apt/archives/$TEST_PKG*.deb arch/
+cd arch
+$APT_GET source -d $TEST_PKG >/dev/null 2>&1
+$APT_FTPARCHIVE packages . | gzip -9 > Packages.gz
+$APT_FTPARCHIVE sources . | gzip -9 > Sources.gz
+cd ..
+
+echo "deb file://$WORKDIR/arch /
+deb-src file://$WORKDIR/arch /" > etc/apt/sources.list
+$APT_GET clean
+
+echo "==== uncompressed indexes from local file:// archive ===="
+echo "--- apt-get update"
+$APT_GET update
+check_indexes
+check_cache
+check_get_source
+
+echo "==== compressed indexes from local file:// archive ===="
+echo "--- apt-get update"
+$APT_GET -o Acquire::GzipIndexes=true update
+# EXFAIL: file:/ URIs currently decompress even with above option
+#check_indexes compressed
+check_indexes
+check_cache
+check_get_source
+
+echo "===== ALL TESTS PASSED ====="