+my %binsrc;
+
+# Lets take pdo database input files for the source mapping
+sub read_bin_src_mapping
+{
+ tie my %src_packages, 'DB_File', "$dbdir/sources_small.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie DB $dbdir/sources_small.db: $!";
+ tie my %src2bin, 'DB_File', "$dbdir/sources_packages.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't open $dbdir/sources_packages.db: $!";
+
+ my %bin;
+ while (my ($source, $data) = each %src_packages) {
+ my @src = map { [ split(/\s+/) ] } split( /\0/, $data );
+ my $newest = (sort( { version_cmp($b->[-1],$a->[-1]) } @src))[0];
+ my ($section, $version) = @{$newest}[2,5];
+
+ my $bin_data = $src2bin{$source};
+ unless ($bin_data) {
+ warn "no binary data found for $source\n";
+ # source packages without binaries have most
+ # likely been succeded
+ next;
+ }
+
+ my @bin = map { [ split(/\s+/) ] } split( /\0/, $bin_data );
+ my %seen;
+ foreach (@bin) {
+ my ($pkg, $ver) = @{$_}[2,3];
+ next if $seen{"$pkg/$ver"}++; # weed out multiple arches/suites faster
+ if ($bin{$pkg}
+ && ($bin{$pkg}{source} ne $source)
+ && (version_cmp($bin{$pkg}{version},$ver) > 0)) {
+ next;
+ } else {
+ $bin{$pkg} = { version => $ver, source => $source,
+ target => "$section" };
+ $binsrc{$pkg} = $source;
+ }
+ }
+ $binsrc{$source} = $source;
+ }
+}