set -u
. "$TESTSDIR"/test.inc

dodo test ! -e dists
mkdir conf db logs lists

for tracking in true false ; do
if $tracking ; then
echo "this is the test variant with tracking on"
else
echo "this is the test variant with tracking off"
fi

if $tracking ; then
cat >> conf/distributions <<EOF

Codename: a
Architectures: abacus source
Components: all
Tracking: minimal
Log: logab

Codename: b
Architectures: abacus
Components: all
Pull: froma
Log: logab
EOF
if test x"${REPREPROOPTIONS#*--verbosedb}" != x"$REPREPROOPTIONS" ; then
	TRACKINGTESTOPTIONS="-D t=1 -D u=1"
else
	TRACKINGTESTOPTIONS="-D t=0 -D u=1"
fi
else
cat >> conf/distributions <<EOF

Codename: a
Architectures: abacus source
Components: all
Log: logab

Codename: b
Architectures: abacus
Components: all
Pull: froma
Log: logab
EOF
TRACKINGTESTOPTIONS="-D t=0 -D u=0"
fi

checknolog logab
cat > conf/pulls <<EOF
Name: froma
From: a
Architectures: froma>toa froma>toa2 froma2>toa2
Components: c1 c2
UDebComponents: u1 u2
EOF
testrun - -b . --export=changed pull a b 3<<EOF
stderr
*=Error parsing ./conf/pulls, line 3, column 16: Unknown architecture 'froma' in Architectures.
-v0*=There have been errors!
return 255
EOF
cp conf/distributions conf/distributions.old
cat >> conf/distributions <<EOF

Codename: moreatoms
Architectures: froma froma2 toa toa2
Components: c1 c2 u1 u2
EOF

testrun - -b . --export=changed pull a b 3<<EOF
stderr
*=(This will simply be ignored and is not even checked when using --fast).
*=Warning: pull rule 'froma' wants to get something from architecture 'froma',
*=Warning: pull rule 'froma' wants to get something from architecture 'froma2',
*=but there is no such architecture in distribution 'a'.
*=Warning: pull rule 'froma' wants to get something from component 'c1',
*=Warning: pull rule 'froma' wants to get something from component 'c2',
*=but there is no such component in distribution 'a'.
*=Warning: pull rule 'froma' wants to get something from udeb component 'u1',
*=Warning: pull rule 'froma' wants to get something from udeb component 'u2',
*=but there is no such udeb component in distribution 'a'.
*=Warning: pull rule 'froma' wants to put something into architecture 'toa',
*=but no distribution using this has such an architecture.
*=Warning: pull rule 'froma' wants to put something into architecture 'toa2',
*=Warning: pull rule 'froma' wants to put something into component 'c1',
*=but no distribution using this has such an component.
*=Warning: pull rule 'froma' wants to put something into component 'c2',
*=Warning: pull rule 'froma' wants to put something into udeb component 'u1',
*=but no distribution using this has such an udeb component.
*=Warning: pull rule 'froma' wants to put something into udeb component 'u2',
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v0*=Installing (and possibly deleting) packages...
EOF
mv conf/distributions.old conf/distributions
testrun - -b . clearvanished 3<<EOF
stderr
stdout
*=Deleting vanished identifier 'moreatoms|c1|froma'.
*=Deleting vanished identifier 'moreatoms|c1|froma2'.
*=Deleting vanished identifier 'moreatoms|c1|toa'.
*=Deleting vanished identifier 'moreatoms|c1|toa2'.
*=Deleting vanished identifier 'moreatoms|c2|froma'.
*=Deleting vanished identifier 'moreatoms|c2|froma2'.
*=Deleting vanished identifier 'moreatoms|c2|toa'.
*=Deleting vanished identifier 'moreatoms|c2|toa2'.
*=Deleting vanished identifier 'moreatoms|u1|froma'.
*=Deleting vanished identifier 'moreatoms|u1|froma2'.
*=Deleting vanished identifier 'moreatoms|u1|toa'.
*=Deleting vanished identifier 'moreatoms|u1|toa2'.
*=Deleting vanished identifier 'moreatoms|u2|froma'.
*=Deleting vanished identifier 'moreatoms|u2|froma2'.
*=Deleting vanished identifier 'moreatoms|u2|toa'.
*=Deleting vanished identifier 'moreatoms|u2|toa2'.
EOF
cat > conf/pulls <<EOF
Name: froma
From: a
EOF
testrun - -b . --export=changed pull a b 3<<EOF
stderr
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
EOF
checklog logab < /dev/null
test ! -d dists/a
test ! -d dists/b
testrun - -b . --export=lookedat pull b 3<<EOF
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
-v0*=Exporting indices...
-v2*=Created directory "./dists"
-v2*=Created directory "./dists/b"
-v2*=Created directory "./dists/b/all"
-v2*=Created directory "./dists/b/all/binary-abacus"
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  creating './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
EOF
checklog logab < /dev/null
test ! -d dists/a
test -d dists/b
testrun - -b . --export=lookedat pull a b 3<<EOF
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
-v0*=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v2*=Created directory "./dists/a"
-v2*=Created directory "./dists/a/all"
-v2*=Created directory "./dists/a/all/binary-abacus"
-v6*= looking for changes in 'a|all|abacus'...
-v6*=  creating './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v2*=Created directory "./dists/a/all/source"
-v6*= looking for changes in 'a|all|source'...
-v6*=  creating './dists/a/all/source/Sources' (gzipped)
EOF
checklog logab < /dev/null
test -d dists/a
test -d dists/b
rm -r dists/a dists/b
DISTRI=a PACKAGE=aa EPOCH="" VERSION=1 REVISION="-1" SECTION="stupid/base" genpackage.sh
testrun - -b . --export=never --delete --delete include a test.changes 3<<EOF
*=Warning: database 'a|all|abacus' was modified but no index file was exported.
*=Warning: database 'a|all|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/all"
-v2*=Created directory "./pool/all/a"
-v2*=Created directory "./pool/all/a/aa"
$(ofa 'pool/all/a/aa/aa-addons_1-1_all.deb')
$(ofa 'pool/all/a/aa/aa_1-1_abacus.deb')
$(ofa 'pool/all/a/aa/aa_1-1.tar.gz')
$(ofa 'pool/all/a/aa/aa_1-1.dsc')
$(opa 'aa-addons' x 'a' 'all' 'abacus' 'deb')
$(opa 'aa' x 'a' 'all' 'abacus' 'deb')
$(opa 'aa' x 'a' 'all' 'source' 'dsc')
$(otta 'a' 'aa')
-v5*=Deleting 'test.changes'.
EOF
checklog logab << EOF
DATESTR add a deb all abacus aa-addons 1-1
DATESTR add a deb all abacus aa 1-1
DATESTR add a dsc all source aa 1-1
EOF
test ! -d dists/a
test ! -d dists/b
test ! -f test.changes
test ! -f aa_1-1_abacus.deb
test ! -f aa_1-1.dsc
test ! -f aa_1-1.tar.gz
test ! -f aa-addons_1-1_all.deb
test -f pool/all/a/aa/aa-addons_1-1_all.deb
test -f pool/all/a/aa/aa_1-1_abacus.deb
test -f pool/all/a/aa/aa_1-1.dsc
test -f pool/all/a/aa/aa_1-1.tar.gz
testout "" -b . dumptracks a
cat >results.expected <<END
Distribution: a
Source: aa
Version: 1-1
Files:
 pool/all/a/aa/aa_1-1.dsc s 1
 pool/all/a/aa/aa_1-1.tar.gz s 1
 pool/all/a/aa/aa_1-1_abacus.deb b 1
 pool/all/a/aa/aa-addons_1-1_all.deb a 1

END
if $tracking; then dodiff results.expected results ; else dodiff /dev/null results ; fi
testrun - -b . export a 3<<EOF
stdout
-v1*=Exporting a...
-v2*=Created directory "./dists/a"
-v2*=Created directory "./dists/a/all"
-v2*=Created directory "./dists/a/all/binary-abacus"
-v6*= exporting 'a|all|abacus'...
-v6*=  creating './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v2*=Created directory "./dists/a/all/source"
-v6*= exporting 'a|all|source'...
-v6*=  creating './dists/a/all/source/Sources' (gzipped)
EOF
checknolog logab
dogrep "Version: 1-1" dists/a/all/binary-abacus/Packages
rm -r dists/a
testout - -b . dumppull b 3<<EOF
stderr
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
add 'aa' - '1-1' 'froma'
add 'aa-addons' - '1-1' 'froma'
EOF
dodiff results results.expected
testrun - -b . --export=changed pull a b 3<<EOF
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
$(opa 'aa' x 'b' 'all' 'abacus' 'deb')
$(opa 'aa-addons' x 'b' 'all' 'abacus' 'deb')
-v0*=Exporting indices...
-v2*=Created directory "./dists/b"
-v2*=Created directory "./dists/b/all"
-v2*=Created directory "./dists/b/all/binary-abacus"
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  creating './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
EOF
checklog logab << EOF
DATESTR add b deb all abacus aa 1-1
DATESTR add b deb all abacus aa-addons 1-1
EOF
test ! -d dists/a
test -d dists/b
dogrep "Version: 1-1" dists/b/all/binary-abacus/Packages
DISTRI=a PACKAGE=aa EPOCH="" VERSION=1 REVISION="-2" SECTION="stupid/base" genpackage.sh
testrun - -b . --export=changed --delete include a test.changes 3<<EOF
stdout
$(ofa 'pool/all/a/aa/aa-addons_1-2_all.deb')
$(ofa 'pool/all/a/aa/aa_1-2_abacus.deb')
$(ofa 'pool/all/a/aa/aa_1-2.tar.gz')
$(ofa 'pool/all/a/aa/aa_1-2.dsc')
$(opu 'aa-addons' x x 'a' 'all' 'abacus' 'deb')
$(opu 'aa' x x 'a' 'all' 'abacus' 'deb')
$(opu 'aa' x x 'a' 'all' 'source' 'dsc')
$(otta 'a' 'aa')
$(ottd 'aa' '1-1' 'a')
-v0*=Exporting indices...
-v2*=Created directory "./dists/a"
-v2*=Created directory "./dists/a/all"
-v2*=Created directory "./dists/a/all/binary-abacus"
-v6*= looking for changes in 'a|all|abacus'...
-v6*=  creating './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v2*=Created directory "./dists/a/all/source"
-v6*= looking for changes in 'a|all|source'...
-v6*=  creating './dists/a/all/source/Sources' (gzipped)
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa_1-1.dsc')
$(ofd 'pool/all/a/aa/aa_1-1.tar.gz')
EOF
checklog logab << EOF
DATESTR replace a deb all abacus aa-addons 1-2 1-1
DATESTR replace a deb all abacus aa 1-2 1-1
DATESTR replace a dsc all source aa 1-2 1-1
EOF
test -f test.changes
test ! -f aa_1-2_abacus.deb
test ! -f aa_1-2.dsc
test ! -f aa_1-2.tar.gz
test ! -f aa-addons_1-2_all.deb
test -d dists/a
dogrep "Version: 1-2" dists/a/all/binary-abacus/Packages
dogrep "Version: 1-1" dists/b/all/binary-abacus/Packages
testout "" -b . dumptracks a
cat >results.expected <<END
Distribution: a
Source: aa
Version: 1-2
Files:
 pool/all/a/aa/aa_1-2.dsc s 1
 pool/all/a/aa/aa_1-2.tar.gz s 1
 pool/all/a/aa/aa_1-2_abacus.deb b 1
 pool/all/a/aa/aa-addons_1-2_all.deb a 1

END
if $tracking; then dodiff results.expected results ; else dodiff /dev/null results ; fi
rm -r dists/a dists/b
testout - -b . dumppull b 3<<EOF
stderr
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
update 'aa' '1-1' '1-2' 'froma'
update 'aa-addons' '1-1' '1-2' 'froma'
EOF
dodiff results results.expected
testrun - -b . --export=changed pull a b 3<<EOF
stderr
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
$(opu 'aa' x x 'b' 'all' 'abacus' 'deb')
$(opu 'aa-addons' x x 'b' 'all' 'abacus' 'deb')
-v0=Exporting indices...
-v2*=Created directory "./dists/b"
-v2*=Created directory "./dists/b/all"
-v2*=Created directory "./dists/b/all/binary-abacus"
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  creating './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa_1-1_abacus.deb')
$(ofd 'pool/all/a/aa/aa-addons_1-1_all.deb')
EOF
checklog logab << EOF
DATESTR replace b deb all abacus aa 1-2 1-1
DATESTR replace b deb all abacus aa-addons 1-2 1-1
EOF
test ! -d dists/a
test -d dists/b
dogrep "Version: 1-2" dists/b/all/binary-abacus/Packages
DISTRI=a PACKAGE=aa EPOCH="" VERSION=1 REVISION="-3" SECTION="stupid/base" genpackage.sh
testrun - -b . --export=never include a test.changes 3<<EOF
*=Warning: database 'a|all|abacus' was modified but no index file was exported.
*=Warning: database 'a|all|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
$(ofa 'pool/all/a/aa/aa-addons_1-3_all.deb')
$(ofa 'pool/all/a/aa/aa_1-3_abacus.deb')
$(ofa 'pool/all/a/aa/aa_1-3.tar.gz')
$(ofa 'pool/all/a/aa/aa_1-3.dsc')
$(opu 'aa-addons' x x 'a' 'all' 'abacus' 'deb')
$(opu 'aa' x x 'a' 'all' 'abacus' 'deb')
$(opu 'aa' x x 'a' 'all' 'source' 'dsc')
$(otta 'a' 'aa')
$(ottd 'aa' '1-2' 'a')
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa_1-2.dsc')
$(ofd 'pool/all/a/aa/aa_1-2.tar.gz')
EOF
checklog logab << EOF
DATESTR replace a deb all abacus aa-addons 1-3 1-2
DATESTR replace a deb all abacus aa 1-3 1-2
DATESTR replace a dsc all source aa 1-3 1-2
EOF
test -f test.changes
test -f aa_1-3_abacus.deb
test -f aa_1-3.dsc
test -f aa_1-3.tar.gz
test -f aa-addons_1-3_all.deb
test ! -f pool/all/a/aa/aa_1-2.dsc
test -f pool/all/a/aa/aa_1-2_abacus.deb # still in b
testout "" -b . dumptracks a
cat >results.expected <<END
Distribution: a
Source: aa
Version: 1-3
Files:
 pool/all/a/aa/aa_1-3.dsc s 1
 pool/all/a/aa/aa_1-3.tar.gz s 1
 pool/all/a/aa/aa_1-3_abacus.deb b 1
 pool/all/a/aa/aa-addons_1-3_all.deb a 1

END
if $tracking; then dodiff results.expected results ; else dodiff /dev/null results ; fi
testout "" -b . dumpunreferenced
dodiff /dev/null results
DISTRI=a PACKAGE=ab EPOCH="" VERSION=2 REVISION="-1" SECTION="stupid/base" genpackage.sh
testrun - -b . --delete --delete --export=never include a test.changes 3<<EOF
stderr
*=Warning: database 'a|all|abacus' was modified but no index file was exported.
*=Warning: database 'a|all|source' was modified but no index file was exported.
=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool/all/a/ab"
$(ofa 'pool/all/a/ab/ab-addons_2-1_all.deb')
$(ofa 'pool/all/a/ab/ab_2-1_abacus.deb')
$(ofa 'pool/all/a/ab/ab_2-1.tar.gz')
$(ofa 'pool/all/a/ab/ab_2-1.dsc')
$(opa 'ab-addons' x 'a' 'all' 'abacus' 'deb')
$(opa 'ab' x 'a' 'all' 'abacus' 'deb')
$(opa 'ab' x 'a' 'all' 'source' 'dsc')
$(otta 'a' 'ab')
-v5*=Deleting 'test.changes'.
EOF
checklog logab << EOF
DATESTR add a deb all abacus ab-addons 2-1
DATESTR add a deb all abacus ab 2-1
DATESTR add a dsc all source ab 2-1
EOF
testout - -b . dumppull b 3<<EOF
stderr
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
update 'aa' '1-2' '1-3' 'froma'
update 'aa-addons' '1-2' '1-3' 'froma'
add 'ab' - '2-1' 'froma'
add 'ab-addons' - '2-1' 'froma'
EOF
dodiff results results.expected

testrun - -b . --export=changed pull b 3<<EOF
stderr
stdout
-v0*=Calculating packages to pull...
-v3*=  pulling into 'b|all|abacus'
-v5*=  looking what to get from 'a|all|abacus'
-v0*=Installing (and possibly deleting) packages...
$(opu 'aa' x x 'b' 'all' 'abacus' 'deb')
$(opu 'aa-addons' x x 'b' 'all' 'abacus' 'deb')
$(opa 'ab' x 'b' 'all' 'abacus' 'deb')
$(opa 'ab-addons' x 'b' 'all' 'abacus' 'deb')
-v0=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  replacing './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa_1-2_abacus.deb')
$(ofd 'pool/all/a/aa/aa-addons_1-2_all.deb')
EOF
checklog logab << EOF
DATESTR replace b deb all abacus aa 1-3 1-2
DATESTR replace b deb all abacus aa-addons 1-3 1-2
DATESTR add b deb all abacus ab 2-1
DATESTR add b deb all abacus ab-addons 2-1
EOF
testout - -b . dumppull b 3<<EOF
stderr
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
keep 'aa' '1-3' '1-3'
keep 'aa-addons' '1-3' '1-3'
keep 'ab' '2-1' '2-1'
keep 'ab-addons' '2-1' '2-1'
EOF
dodiff results results.expected
dogrep "Version: 1-3" dists/b/all/binary-abacus/Packages
dogrep "Version: 2-1" dists/b/all/binary-abacus/Packages
test ! -f pool/all/a/aa/aa_1-2_abacus.deb
test -f pool/all/a/aa/aa_1-3_abacus.deb
DISTRI=a PACKAGE=ab EPOCH="" VERSION=3 REVISION="-1" SECTION="stupid/base" genpackage.sh
grep -v '\.tar\.gz' test.changes > broken.changes
testrun - -b . --delete --delete include a broken.changes 3<<EOF
*=I don't know what to do having a .dsc without a .diff.gz or .tar.gz in 'broken.changes'!
-v0*=There have been errors!
returns 255
EOF
checknolog logab
echo " $EMPTYMD5 stupid/base superfluous ab_3-1.diff.gz" >> broken.changes
testrun - -b . --delete --delete include a broken.changes 3<<EOF
*=Cannot find file './ab_3-1.diff.gz' needed by 'broken.changes'!
-v0*=There have been errors!
returns 249
EOF
checknolog logab
test -f broken.changes
test ! -f ab_3-1.diff.gz
test -f ab-addons_3-1_all.deb
test -f ab_3-1_abacus.deb
test -f ab_3-1.dsc
test ! -f pool/all/a/ab/ab_3-1.diff.gz
test ! -f pool/all/a/ab/ab-addons_3-1_all.deb
test ! -f pool/all/a/ab/ab_3-1_abacus.deb
test ! -f pool/all/a/ab/ab_3-1.dsc
touch ab_3-1.diff.gz
testrun - -b . --delete -T deb include a broken.changes 3<<EOF
stdout
$(ofa 'pool/all/a/ab/ab-addons_3-1_all.deb')
$(ofa 'pool/all/a/ab/ab_3-1_abacus.deb')
$(opu 'ab-addons' x x 'a' 'all' 'abacus' 'deb')
$(opu 'ab' x x 'a' 'all' 'abacus' 'deb')
$(otta 'a' 'ab')
-v0*=Exporting indices...
-v2*=Created directory "./dists/a"
-v2*=Created directory "./dists/a/all"
-v2*=Created directory "./dists/a/all/binary-abacus"
-v6*= looking for changes in 'a|all|abacus'...
-v6*=  creating './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v2*=Created directory "./dists/a/all/source"
-v6*= looking for changes in 'a|all|source'...
-v6*=  creating './dists/a/all/source/Sources' (gzipped)
EOF
checklog logab <<EOF
DATESTR replace a deb all abacus ab-addons 3-1 2-1
DATESTR replace a deb all abacus ab 3-1 2-1
EOF
testout "" -b . dumpunreferenced
dodiff /dev/null results
test -f broken.changes
test -f ab_3-1.diff.gz
test ! -f ab-addons_3-1_all.deb
test ! -f ab_3-1_abacus.deb
test -f ab_3-1.dsc
test ! -f pool/all/a/ab/ab_3-1.diff.gz
test -f pool/all/a/ab/ab-addons_3-1_all.deb
test -f pool/all/a/ab/ab_3-1_abacus.deb
test ! -f pool/all/a/ab/ab_3-1.dsc
testout "" -b . dumptracks a
cat >results.expected <<END
Distribution: a
Source: aa
Version: 1-3
Files:
 pool/all/a/aa/aa_1-3.dsc s 1
 pool/all/a/aa/aa_1-3.tar.gz s 1
 pool/all/a/aa/aa_1-3_abacus.deb b 1
 pool/all/a/aa/aa-addons_1-3_all.deb a 1

Distribution: a
Source: ab
Version: 2-1
Files:
 pool/all/a/ab/ab_2-1.dsc s 1
 pool/all/a/ab/ab_2-1.tar.gz s 1

Distribution: a
Source: ab
Version: 3-1
Files:
 pool/all/a/ab/ab_3-1_abacus.deb b 1
 pool/all/a/ab/ab-addons_3-1_all.deb a 1

END
if $tracking; then dodiff results.expected results ; else dodiff /dev/null results ; fi
testout "" -b . dumpunreferenced
dodiff /dev/null results
testrun - -b . --delete --delete include a broken.changes 3<<EOF
*=Unable to find pool/all/a/ab/ab_3-1.tar.gz needed by ab_3-1.dsc!
*=Perhaps you forgot to give dpkg-buildpackage the -sa option,
= or you could try --ignore=missingfile to guess possible files to use.
-v0*=There have been errors!
stdout
$(ofa 'pool/all/a/ab/ab_3-1.dsc')
$(ofa 'pool/all/a/ab/ab_3-1.diff.gz')
-v0*=Deleting files just added to the pool but not used.
-v0*=(to avoid use --keepunusednewfiles next time)
$(ofd 'pool/all/a/ab/ab_3-1.diff.gz')
$(ofd 'pool/all/a/ab/ab_3-1.dsc')
returns 249
EOF
test -f broken.changes
test -f ab_3-1.diff.gz
test ! -f ab-addons_3-1_all.deb
test ! -f ab_3-1_abacus.deb
test -f ab_3-1.dsc
test ! -f pool/all/a/ab/ab_3-1.diff.gz
test -f pool/all/a/ab/ab-addons_3-1_all.deb
test -f pool/all/a/ab/ab_3-1_abacus.deb
test ! -f pool/all/a/ab/ab_3-1.dsc
cat broken.changes
testrun - -b . -T dsc --delete --delete --ignore=missingfile include a broken.changes 3<<EOF
*=Unable to find pool/all/a/ab/ab_3-1.tar.gz!
*=Perhaps you forgot to give dpkg-buildpackage the -sa option.
*=--ignore=missingfile was given, searching for file...
stdout
$(ofa 'pool/all/a/ab/ab_3-1.tar.gz')
$(ofa 'pool/all/a/ab/ab_3-1.diff.gz')
$(ofa 'pool/all/a/ab/ab_3-1.dsc')
$(opu 'ab' x x 'a' 'all' 'source' 'dsc')
$(ottd 'ab' '2-1' 'a')
-v0*=Deleting files just added to the pool but not used.
-v0*=(to avoid use --keepunusednewfiles next time)
$(ofd 'pool/all/a/ab/ab_3-1.diff.gz')
-v5*=Deleting 'broken.changes'.
-v0*=Exporting indices...
-v6*= looking for changes in 'a|all|abacus'...
-v6*= looking for changes in 'a|all|source'...
-v6*=  replacing './dists/a/all/source/Sources' (gzipped)
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/ab/ab_2-1.dsc')
$(ofd 'pool/all/a/ab/ab_2-1.tar.gz')
EOF
checklog logab <<EOF
DATESTR replace a dsc all source ab 3-1 2-1
EOF
test ! -f broken.changes
test ! -f ab_3-1.diff.gz
test ! -f ab-addons_3-1_all.deb
test ! -f ab_3-1_abacus.deb
test ! -f ab_3-1.dsc
test ! -f pool/all/a/ab/ab_3-1.diff.gz
test -f pool/all/a/ab/ab-addons_3-1_all.deb
test -f pool/all/a/ab/ab_3-1_abacus.deb
test -f pool/all/a/ab/ab_3-1.dsc
testout "" -b . dumpunreferenced
cat > results.expected << EOF
pool/all/a/ab/ab_3-1.diff.gz
EOF
dodiff /dev/null results || dodiff results.expected results
testrun - -b . deleteunreferenced 3<<EOF
stdout
$(ofd 'pool/all/a/ab/ab_3-1.diff.gz' true '')
EOF

DISTRI=b PACKAGE=ac EPOCH="" VERSION=1 REVISION="-1" SECTION="stupid/base" genpackage.sh
testrun - -b . -A abacus --delete --delete --ignore=missingfile include b test.changes 3<<EOF
stderr
-v2*=Skipping 'ac_1-1.dsc' as architecture 'source' is not in the requested set.
-v2*=Skipping 'ac_1-1.tar.gz' as architecture 'source' is not in the requested set.
-v3*=Limiting 'ac-addons_1-1_all.deb' to architectures abacus as requested.
stdout
-v2*=Created directory "./pool/all/a/ac"
$(ofa 'pool/all/a/ac/ac-addons_1-1_all.deb')
$(ofa 'pool/all/a/ac/ac_1-1_abacus.deb')
$(opa 'ac-addons' x 'b' 'all' 'abacus' 'deb')
$(opa 'ac' x 'b' 'all' 'abacus' 'deb')
-v5*=Deleting 'test.changes'.
-v0*=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  replacing './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
EOF
checklog logab <<EOF
DATESTR add b deb all abacus ac-addons 1-1
DATESTR add b deb all abacus ac 1-1
EOF
dogrep '^Package: aa$' dists/b/all/binary-abacus/Packages
dogrep '^Package: aa-addons$' dists/b/all/binary-abacus/Packages
dogrep '^Package: ab$' dists/b/all/binary-abacus/Packages
dogrep '^Package: ab-addons$' dists/b/all/binary-abacus/Packages
dogrep '^Package: ac$' dists/b/all/binary-abacus/Packages
dogrep '^Package: ac-addons$' dists/b/all/binary-abacus/Packages
echo "Update: - froma" >> conf/distributions
cat >conf/updates <<END
Name: froma
Method: copy:$WORKDIR
VerifyRelease: blindtrust
Suite: a
GetInRelease: no
ListHook: /bin/cp
END
testout - -b . dumpupdate b 3<<EOF
-v6*=aptmethod start 'copy:$WORKDIR/dists/a/Release'
-v1*=aptmethod got 'copy:$WORKDIR/dists/a/Release'
-v6*=aptmethod start 'copy:$WORKDIR/dists/a/all/binary-abacus/Packages.gz'
-v1*=aptmethod got 'copy:$WORKDIR/dists/a/all/binary-abacus/Packages.gz'
-v2*=Uncompress './lists/froma_a_all_abacus_Packages.gz' into './lists/froma_a_all_abacus_Packages' using '/bin/gunzip'...
-v6*=Called /bin/cp './lists/froma_a_all_abacus_Packages' './lists/_b_all_abacus_froma_froma_a_all_abacus_Packages'
-v6*=Listhook successfully returned!
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
keep 'aa' '1-3' '1-3'
keep 'aa-addons' '1-3' '1-3'
update 'ab' '2-1' '3-1' 'froma'
update 'ab-addons' '2-1' '3-1' 'froma'
delete 'ac' '1-1'
delete 'ac-addons' '1-1'
EOF
dodiff results.expected results
testrun - -b . predelete b 3<<EOF
=WARNING: Single-Instance not yet supported!
-v6*=aptmethod start 'copy:$WORKDIR/dists/a/Release'
-v1*=aptmethod got 'copy:$WORKDIR/dists/a/Release'
-v6*=Called /bin/cp './lists/froma_a_all_abacus_Packages' './lists/_b_all_abacus_froma_froma_a_all_abacus_Packages'
-v6*=Listhook successfully returned!
stdout
-v0*=Removing obsolete or to be replaced packages...
-v3*=  processing updates for 'b|all|abacus'
-v5*=  marking everything to be deleted
-v5*=  reading './lists/_b_all_abacus_froma_froma_a_all_abacus_Packages'
$(opd 'ab' x b all abacus deb)
$(opd 'ab-addons' x b all abacus deb)
$(opd 'ac' x b all abacus deb)
$(opd 'ac-addons' x b all abacus deb)
-v0*=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  replacing './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
-v1*=Shutting down aptmethods...
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/ab/ab_2-1_abacus.deb')
$(ofd 'pool/all/a/ab/ab-addons_2-1_all.deb')
$(ofd 'pool/all/a/ac/ac_1-1_abacus.deb')
$(ofd 'pool/all/a/ac/ac-addons_1-1_all.deb')
-v2*=removed now empty directory ./pool/all/a/ac
EOF
testout - -b . dumpupdate b 3<<EOF
-v6*=aptmethod start 'copy:$WORKDIR/dists/a/Release'
-v1*=aptmethod got 'copy:$WORKDIR/dists/a/Release'
-v6*=Called /bin/cp './lists/froma_a_all_abacus_Packages' './lists/_b_all_abacus_froma_froma_a_all_abacus_Packages'
-v6*=Listhook successfully returned!
EOF
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
keep 'aa' '1-3' '1-3'
keep 'aa-addons' '1-3' '1-3'
add 'ab' - '3-1' 'froma'
add 'ab-addons' - '3-1' 'froma'
EOF
dodiff results.expected results
checklog logab <<EOF
DATESTR remove b deb all abacus ab 2-1
DATESTR remove b deb all abacus ab-addons 2-1
DATESTR remove b deb all abacus ac 1-1
DATESTR remove b deb all abacus ac-addons 1-1
EOF
dogrep '^Package: aa$' dists/b/all/binary-abacus/Packages
dogrep '^Package: aa-addons$' dists/b/all/binary-abacus/Packages
dongrep '^Package: ab$' dists/b/all/binary-abacus/Packages
dongrep '^Package: ab-addons$' dists/b/all/binary-abacus/Packages
dongrep '^Package: ac$' dists/b/all/binary-abacus/Packages
dongrep '^Package: ac-addons$' dists/b/all/binary-abacus/Packages
test ! -f pool/all/a/ac/ac-addons_1-1_all.deb
test ! -f pool/all/a/ab/ab_2-1_abacus.deb
test -f pool/all/a/aa/aa_1-3_abacus.deb
testrun - -b . copy b a ab ac 3<<EOF
stderr
-v0*=Will not copy as not found: ac.
stdout
-v9*=Adding reference to 'pool/all/a/ab/ab_3-1_abacus.deb' by 'b|all|abacus'
-v1*=Adding 'ab' '3-1' to 'b|all|abacus'.
-v3*=Not looking into 'a|all|source' as no matching target in 'b'!
$(opa 'ab' x 'b' 'all' 'abacus' 'deb')
-v0*=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  replacing './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
EOF
# readd?
#-v3*=No instance of 'ab' found in 'a|all|source'!
#-v3*=No instance of 'ac' found in 'a|all|abacus'!
#-v3*=No instance of 'ac' found in 'a|all|source'!
checklog logab <<EOF
DATESTR add b deb all abacus ab 3-1
EOF
if $tracking ; then
testout "" -b . dumptracks
cat > results.expected <<EOF
Distribution: a
Source: aa
Version: 1-3
Files:
 pool/all/a/aa/aa_1-3.dsc s 1
 pool/all/a/aa/aa_1-3.tar.gz s 1
 pool/all/a/aa/aa_1-3_abacus.deb b 1
 pool/all/a/aa/aa-addons_1-3_all.deb a 1

Distribution: a
Source: ab
Version: 3-1
Files:
 pool/all/a/ab/ab_3-1_abacus.deb b 1
 pool/all/a/ab/ab-addons_3-1_all.deb a 1
 pool/all/a/ab/ab_3-1.dsc s 1
 pool/all/a/ab/ab_3-1.tar.gz s 1

EOF
dodiff results.expected results
testout "" -b . dumpreferences
sort results > results.sorted
cat > results.expected <<EOF
a aa 1-3 pool/all/a/aa/aa-addons_1-3_all.deb
a aa 1-3 pool/all/a/aa/aa_1-3.dsc
a aa 1-3 pool/all/a/aa/aa_1-3.tar.gz
a aa 1-3 pool/all/a/aa/aa_1-3_abacus.deb
a ab 3-1 pool/all/a/ab/ab-addons_3-1_all.deb
a ab 3-1 pool/all/a/ab/ab_3-1.dsc
a ab 3-1 pool/all/a/ab/ab_3-1.tar.gz
a ab 3-1 pool/all/a/ab/ab_3-1_abacus.deb
a|all|abacus pool/all/a/aa/aa-addons_1-3_all.deb
a|all|abacus pool/all/a/aa/aa_1-3_abacus.deb
a|all|abacus pool/all/a/ab/ab-addons_3-1_all.deb
a|all|abacus pool/all/a/ab/ab_3-1_abacus.deb
a|all|source pool/all/a/aa/aa_1-3.dsc
a|all|source pool/all/a/aa/aa_1-3.tar.gz
a|all|source pool/all/a/ab/ab_3-1.dsc
a|all|source pool/all/a/ab/ab_3-1.tar.gz
b|all|abacus pool/all/a/aa/aa-addons_1-3_all.deb
b|all|abacus pool/all/a/aa/aa_1-3_abacus.deb
b|all|abacus pool/all/a/ab/ab_3-1_abacus.deb
EOF
dodiff results.expected results.sorted
fi
rm -r -f db2
cp -a db db2
echo tracking is $tracking
testrun - --keepunreferenced --dbdir ./db2 -b . removesrc a unknown 3<<EOF
stderr
-u1*=Nothing about source package 'unknown' found in the tracking data of 'a'!
-u1*=This either means nothing from this source in this version is there,
-u1*=or the tracking information might be out of date.
stdout
EOF
testrun - --keepunreferenced --dbdir ./db2 -b . removesrc a ab 3-1 3<<EOF
stdout
$(opd 'ab-addons' x a all abacus deb)
$(opd 'ab' x a all abacus deb)
$(opd 'ab' x a all source dsc)
$(ottd 'ab' '3-1' 'a')
-v0*=Exporting indices...
-v6*= looking for changes in 'a|all|abacus'...
-v6*=  replacing './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v6*= looking for changes in 'a|all|source'...
-v6*=  replacing './dists/a/all/source/Sources' (gzipped)
-v1*=3 files lost their last reference.
-v1*=(dumpunreferenced lists such files, use deleteunreferenced to delete them.)
EOF
if $tracking ; then
checklog logab <<EOF
DATESTR remove a deb all abacus ab-addons 3-1
DATESTR remove a deb all abacus ab 3-1
DATESTR remove a dsc all source ab 3-1
EOF
else
checklog logab <<EOF
DATESTR remove a deb all abacus ab 3-1
DATESTR remove a deb all abacus ab-addons 3-1
DATESTR remove a dsc all source ab 3-1
EOF
fi
rm -r db2
cp -a db db2
testrun - --keepunreferenced --dbdir ./db2 -b . removesrc a ab 3<<EOF
stdout
$(opd 'ab-addons' unset a all abacus deb)
$(opd 'ab' unset a all abacus deb)
$(opd 'ab' unset a all source deb)
$(ottd 'ab' '3-1' 'a')
-v0*=Exporting indices...
-v6*= looking for changes in 'a|all|abacus'...
-v6*=  replacing './dists/a/all/binary-abacus/Packages' (uncompressed,gzipped)
-v6*= looking for changes in 'a|all|source'...
-v6*=  replacing './dists/a/all/source/Sources' (gzipped)
-v1*=3 files lost their last reference.
-v1*=(dumpunreferenced lists such files, use deleteunreferenced to delete them.)
EOF
if $tracking ; then
checklog logab <<EOF
DATESTR remove a deb all abacus ab-addons 3-1
DATESTR remove a deb all abacus ab 3-1
DATESTR remove a dsc all source ab 3-1
EOF
else
checklog logab <<EOF
DATESTR remove a deb all abacus ab 3-1
DATESTR remove a deb all abacus ab-addons 3-1
DATESTR remove a dsc all source ab 3-1
EOF
fi
testout "" --keepunreferenced --dbdir ./db2 dumppull
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
keep 'aa' '1-3' '1-3'
keep 'aa-addons' '1-3' '1-3'
keep 'ab' '3-1' unavailable
EOF
dodiff results.expected results
testrun - --keepunreferenced --dbdir ./db2 -b . removefilter b "Version (== 1-3), Package (>> aa)" 3<<EOF
stdout
$(opd 'aa-addons' unset b all abacus deb)
-v0*=Exporting indices...
-v6*= looking for changes in 'b|all|abacus'...
-v6*=  replacing './dists/b/all/binary-abacus/Packages' (uncompressed,gzipped)
EOF
checklog logab <<EOF
DATESTR remove b deb all abacus aa-addons 1-3
EOF
testout "" --keepunreferenced --dbdir ./db2 dumppull
cat > results.expected <<EOF
Updates needed for 'b|all|abacus':
keep 'aa' '1-3' '1-3'
add 'aa-addons' - '1-3' 'froma'
keep 'ab' '3-1' unavailable
EOF
dodiff results.expected results
if $tracking ; then
testrun - -b . --delete removealltracks a 3<<EOF
stdout
-v0*=Deleting all tracks for a...
EOF
testout "" -b . dumptracks
dodiff /dev/null results
fi
testout "" -b . dumpreferences
sort results > results.sorted
cat > results.expected <<EOF
a|all|abacus pool/all/a/aa/aa-addons_1-3_all.deb
a|all|abacus pool/all/a/aa/aa_1-3_abacus.deb
a|all|abacus pool/all/a/ab/ab-addons_3-1_all.deb
a|all|abacus pool/all/a/ab/ab_3-1_abacus.deb
a|all|source pool/all/a/aa/aa_1-3.dsc
a|all|source pool/all/a/aa/aa_1-3.tar.gz
a|all|source pool/all/a/ab/ab_3-1.dsc
a|all|source pool/all/a/ab/ab_3-1.tar.gz
b|all|abacus pool/all/a/aa/aa-addons_1-3_all.deb
b|all|abacus pool/all/a/aa/aa_1-3_abacus.deb
b|all|abacus pool/all/a/ab/ab_3-1_abacus.deb
EOF
dodiff results.expected results.sorted
cat > conf/distributions <<EOF
Codename: X
Architectures: none
Components: test
EOF
checknolog logab
if $tracking ; then
testrun - -b . --delete clearvanished 3<<EOF
-v4*=Strange, 'X|test|none' does not appear in packages.db yet.
stdout
*=Deleting vanished identifier 'a|all|abacus'.
*=Deleting vanished identifier 'a|all|source'.
*=Deleting vanished identifier 'b|all|abacus'.
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa-addons_1-3_all.deb')
$(ofd 'pool/all/a/aa/aa_1-3.dsc')
$(ofd 'pool/all/a/aa/aa_1-3.tar.gz')
$(ofd 'pool/all/a/aa/aa_1-3_abacus.deb')
-v2*=removed now empty directory ./pool/all/a/aa
$(ofd 'pool/all/a/ab/ab-addons_3-1_all.deb')
$(ofd 'pool/all/a/ab/ab_3-1.dsc')
$(ofd 'pool/all/a/ab/ab_3-1.tar.gz')
$(ofd 'pool/all/a/ab/ab_3-1_abacus.deb')
-v2*=removed now empty directory ./pool/all/a/ab
-v2*=removed now empty directory ./pool/all/a
-v2*=removed now empty directory ./pool/all
-v2*=removed now empty directory ./pool
EOF
else
testrun - -b . --delete clearvanished 3<<EOF
# -v4*=Strange, 'X|test|none' does not appear in packages.db yet.
stdout
*=Deleting vanished identifier 'a|all|abacus'.
*=Deleting vanished identifier 'a|all|source'.
*=Deleting vanished identifier 'b|all|abacus'.
-v0*=Deleting files no longer referenced...
$(ofd 'pool/all/a/aa/aa-addons_1-3_all.deb')
$(ofd 'pool/all/a/aa/aa_1-3.dsc')
$(ofd 'pool/all/a/aa/aa_1-3.tar.gz')
$(ofd 'pool/all/a/aa/aa_1-3_abacus.deb')
-v2*=removed now empty directory ./pool/all/a/aa
$(ofd 'pool/all/a/ab/ab-addons_3-1_all.deb')
$(ofd 'pool/all/a/ab/ab_3-1.dsc')
$(ofd 'pool/all/a/ab/ab_3-1.tar.gz')
$(ofd 'pool/all/a/ab/ab_3-1_abacus.deb')
-v2*=removed now empty directory ./pool/all/a/ab
-v2*=removed now empty directory ./pool/all/a
-v2*=removed now empty directory ./pool/all
-v2*=removed now empty directory ./pool
EOF
fi
checknolog logab
testout "" -b . dumptracks
dodiff /dev/null results
testout "" -b . dumpunreferenced
dodiff /dev/null results
rm -r dists
done
rm -r db db2 conf lists logs
rm aa* ab* ac* results.log.expected results.expected results results.sorted
testsuccess
