1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#!/bin/sh
set -e
db_dump=db_dump
if command -v db_dump-5 >/dev/null 2>&1; then
db_dump=db_dump-5
fi
ensure_correct_packages_file() {
testequal "Package: foo
Architecture: i386
Version: 1
Priority: optional
Section: others
Maintainer: Joe Sixpack <joe@example.org>
$(dpkg-deb -I ./aptarchive/pool/main/foo_1_i386.deb | grep 'Installed-Size:' | sed 's#^ ##')
Filename: pool/main/foo_1_i386.deb" head -n8 ./aptarchive/dists/test/main/binary-i386/Packages
}
ensure_correct_contents_file() {
testfileequal ./aptarchive/dists/test/Contents-i386 "usr/bin/foo-i386 others/foo
usr/share/doc/foo/FEATURES others/foo
usr/share/doc/foo/changelog others/foo
usr/share/doc/foo/copyright others/foo"
}
#
# main()
#
TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
setupenvironment
configarchitecture 'i386'
mkdir -p aptarchive/dists/test/main/i18n/
mkdir -p aptarchive/dists/test/main/source/
mkdir -p aptarchive/dists/test/main/binary-i386
mkdir -p aptarchive/pool/main
mkdir aptarchive-overrides
touch aptarchive-overrides/bin-override
touch aptarchive-overrides/extra-override
mkdir aptarchive-cache
cat > ftparchive.conf <<"EOF"
Dir {
ArchiveDir "./aptarchive";
OverrideDir "./aptarchive-overrides";
CacheDir "./aptarchive-cache";
};
Default {
Packages::Compress ". gzip bzip2";
Contents::Compress ". gzip bzip2";
LongDescription "false";
};
TreeDefault {
BinCacheDB "packages-$(SECTION)-$(ARCH).db";
Directory "pool/$(SECTION)";
SrcDirectory "pool/$(SECTION)";
Packages "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages";
Contents "$(DIST)/Contents-$(ARCH)";
};
Tree "dists/test" {
Sections "main";
Architectures "i386";
BinOverride "bin-override";
ExtraOverride "extra-override";
//FileList "file-list";
};
EOF
# build one package
buildsimplenativepackage 'foo' 'i386' '1' 'test'
mv incoming/* aptarchive/pool/main/
# generate (empty cachedb)
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
cp rootdir/tmp/testsuccess.output stats-out.txt
ensure_correct_packages_file
ensure_correct_contents_file
testsuccessequal ' Misses in Cache: 2
dists/test/Contents-i386: New 402 B Misses in Cache: 0' grep Misses stats-out.txt
# generate again
# ensure Contents file is not newer than Packages file; to avoid a race condition with the
# test case: If Contents file happened to be newer than the Packages file, we'd skip its
# generation (failing the test case); but if they are generated at the same time it may
# be out-of-date strictly speaking and needed regenerating.
touch -r ./aptarchive/dists/test/main/binary-i386/Packages ./aptarchive/dists/test/Contents-i386*
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
cp rootdir/tmp/testsuccess.output stats-out.txt
ensure_correct_packages_file
ensure_correct_contents_file
testsuccessequal ' Misses in Cache: 0
dists/test/Contents-i386: Misses in Cache: 0' grep Misses stats-out.txt
# and again (with removing the Packages file)
rm -f ./aptarchive/dists/test/main/binary-i386/*
rm -f ./aptarchive/dists/test/Contents-i386
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
cp rootdir/tmp/testsuccess.output stats-out.txt
ensure_correct_packages_file
ensure_correct_contents_file
testsuccessequal ' Misses in Cache: 0
dists/test/Contents-i386: New 402 B Misses in Cache: 0' grep Misses stats-out.txt
msgmsg "Test overrides"
manyX=$(head -c2000 /dev/zero | tr '\0' 'X')
echo "foo priority${manyX} overrideSection" > aptarchive-overrides/bin-override
echo "foo Extra ${manyX}trailer" > aptarchive-overrides/extra-override
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages
msgmsg "Test long paths"
x128=$(head -c 128 /dev/zero | tr '\0' 'X')
longPath=${x128}/${x128}/${x128}/${x128}/${x128}/${x128}/${x128}/${x128}
mkdir -p aptarchive/pool/main/$longPath
mv aptarchive/pool/main/foo_1_i386.deb aptarchive/pool/main/$longPath/foo_1_i386.deb
# before
testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db
testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cl$" dump
testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cn$" dump
testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:st$" dump
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
# file is still found
testsuccessequal "Filename: pool/main/${longPath}/foo_1_i386.deb" grep ^Filename ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages
# file is in the database
testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cl$" dump
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cn$" dump
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:st"$ dump
msgmsg "Test file lists"
# Check that the empty file list produces no packages
rm aptarchive-cache/packages-main-i386.db
testsuccess sed -i s#//FileList#FileList# ftparchive.conf
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
testfileequal ./aptarchive/dists/test/main/binary-i386/Packages ""
# Add the packages and run our checks again
echo "pool/main/${longPath}/foo_1_i386.deb" > file-list
testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
testsuccessequal "Filename: pool/main/${longPath}/foo_1_i386.deb" grep ^Filename ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages
testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages
# file is in the database
testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cl$" dump
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cn$" dump
testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:st"$ dump
msgmsg "Test Clean"
# and clean
rm -rf aptarchive/pool/main/*
testsuccessequal "packages-main-i386.db" aptftparchive clean ftparchive.conf
testsuccess aptftparchive clean ftparchive.conf -o Debug::APT::FTPArchive::Clean=1
cp rootdir/tmp/testsuccess.output clean-out.txt
testsuccessequal "0 Number of unique keys in the tree" grep unique clean-out.txt
testsuccessequal "packages-main-i386.db" grep packages-main-i386.db clean-out.txt
|