# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
+use warnings;
use lib './lib';
+$| = 1;
+
my $what = $ARGV[0] ? "non-free" : "*";
# max. distinct results for a given package postfix
my $MAX_PACKAGE_POSTFIXES = 100;
use DB_File;
use Storable;
+use Deb::Versions;
use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
&Packages::Config::init( './' );
my %packages_small = ();
+my %virtual_packages = ();
my %package_names = ();
my %package_postfixes = ();
my %sources_packages = ();
$/ = "";
-for my $archive (@ARCHIVES) {
- for my $suite (@SUITES) {
+for my $suite (@SUITES) {
+ my %package_names_suite = ();
+ my %packages_all_db;
+ tie %packages_all_db, "DB_File", "$DBDIR/packages_all_$suite.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
- my %virtual_packages = ();
+ for my $archive (@ARCHIVES) {
print "Reading $archive/$suite...\n";
- my %packages_all_db;
- tie %packages_all_db, "DB_File", "$DBDIR/packages_all_$suite.db.new",
- O_RDWR|O_CREAT, 0666, $DB_BTREE
- or die "Error creating DB: $!";
open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/{,debian-installer/}binary-*/Packages.gz|";
while (<PKG>) {
next if /^\s*$/;
if ($data{'provides'}) {
foreach (split /\s*,\s*/, $data{'provides'}) {
- $virtual_packages{$_}{$data{'package'}}++;
+ $virtual_packages{$_}{$suite}{$data{'package'}}++;
+ $packages_small{$_} ||= {};
}
}
$package_names{$data{'package'}} = 1;
+ $package_names_suite{$data{'package'}} = 1;
my $src = $data{'package'};
my $src_version = '';
if ($data{'source'}) {
$data{'section'} = $section;
$data{'subsection'} = $subsection;
$data{'priority'} ||= '-';
- $sections{$suite}{$archive}{$section}++;
- $subsections{$suite}{$archive}{$subsection}++;
- $priorities{$suite}{$archive}{$data{priority}}++;
- $packages_small{$data{'package'}} .= "$archive $suite $data{'architecture'} ".
- "$section $subsection $data{'priority'} $data{'version'} $sdescr\000";
+ $sections{$suite}{$section}++;
+ $subsections{$suite}{$subsection}++;
+ $priorities{$suite}{$data{priority}}++;
+ my $pkgitem = "$archive $suite $data{'architecture'} ".
+ "$section $subsection $data{'priority'} $data{'version'} $sdescr\0";
+ my $previtem = ($packages_small{$data{'package'}}{$suite}{$data{'architecture'}}
+ ||= $pkgitem);
+ $packages_small{$data{'package'}}{$suite}{$data{'architecture'}} = $pkgitem
+ if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) > 0;
+ $previtem = ($packages_small{$data{'package'}}{$suite}{'any'}
+ ||= $pkgitem);
+ $packages_small{$data{'package'}}{$suite}{'any'} = $pkgitem
+ if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) > 0;
$sources_packages{$src} .=
"$archive $suite $data{'package'} $data{'version'} $data{'architecture'}\000";
$data{archive} = $archive;
$packages_all_db{"$data{'package'} $data{'architecture'} $data{'version'}"}
= $data;
}
+ }
- foreach (keys %virtual_packages) {
- my @provided_by = keys %{$virtual_packages{$_}};
- $packages_small{$_} .= "$archive $suite virtual v v v v @provided_by\000";
- }
-
- untie %packages_all_db;
+ open NAMES, '>', "$DBDIR/package_names_$suite.txt.new"
+ or die "Error creating package names list: $!";
+ foreach (sort keys %package_names_suite) {
+ print NAMES "$_\n";
}
+ close NAMES;
+
+ untie %packages_all_db;
}
print "Writing databases...\n";
tie %packages_small_db, "DB_File", "$DBDIR/packages_small.db.new",
O_RDWR|O_CREAT, 0666, $DB_BTREE
or die "Error creating DB: $!";
-while (my ($k, $v) = each(%packages_small)) {
- $v =~ s/.$//s;
- $packages_small_db{$k} = $v;
+while (my ($pkg, $v) = each(%packages_small)) {
+ my ($res1, $res2, $res3) = ("", "", "");
+ while (my ($suite, $v2) = each %$v) {
+ $res2 .= $v2->{'any'};
+ while (my ($arch, $v3) = each %$v2) {
+ next if $arch eq 'any' or $v3 eq $v2->{'any'};
+ $res3 .= $v3;
+ }
+ }
+
+ if (exists $virtual_packages{$pkg}) {
+ while (my ($suite, $v2) = each %{$virtual_packages{$pkg}}) {
+ $res1 .= "$suite\01".(join ' ', keys %$v2)."\01";
+ }
+ } else {
+ $res1 .= "-\01-\01";
+ }
+ $res1 =~ s/.$/\0/s;
+
+ my $res = "$res1$res2$res3";
+ $res =~ s/.$//s;
+ $packages_small_db{$pkg} = $res;
}
untie %packages_small_db;
for my $suite (@SUITES) {
rename("$DBDIR/packages_all_$suite.db.new",
"$DBDIR/packages_all_$suite.db");
+ rename("$DBDIR/package_names_$suite.txt.new",
+ "$DBDIR/package_names_$suite.txt");
}
rename("$DBDIR/packages_descriptions.db.new",
"$DBDIR/packages_descriptions.db");