# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
+use lib './lib';
-use DB_File;
+my $what = $ARGV[0] ? "non-free" : "*";
+# max. distinct results for a given package postfix
+my $MAX_SOURCE_POSTFIXES = 100;
-my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
+use DB_File;
+use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
+&Packages::Config::init( './' );
+my %sources_small = ();
+my %source_names = ();
+my %source_postfixes = ();
$/ = "";
-for my $suite (@suites) {
+for my $archive (@ARCHIVES) {
+ for my $suite (@SUITES) {
- print "Reading $suite...\n";
+ print "Reading $archive/$suite...\n";
my %sources_all_db;
- tie %sources_all_db, "DB_File", "sources_all_$suite.db.new",
+ tie %sources_all_db, "DB_File", "$DBDIR/sources_all_$suite.db.new",
O_RDWR|O_CREAT, 0666, $DB_BTREE
or die "Error creating DB: $!";
- open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/non-free/source/Sources.gz|";
+ open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/source/Sources.gz|";
while (<PKG>) {
next if /^\s*$/;
my $data = "";
$key =~ tr [A-Z] [a-z];
$data{$key} = $value;
}
+ $data .= "Archive: $archive\n";
$sources_all_db{"$data{'package'} $data{'version'}"}
= $data;
+
+ $source_names{$data{'package'}} = 1;
+
+ my $section = 'main';
+ my $subsection = $data{section} || '-';
+ if ($data{section} && ($data{section} =~ m=/=o)) {
+ ($section, $subsection) = split m=/=o, $data{section}, 2;
+ }
+ $data{'priority'} = "-" if not exists($data{'priority'});
+ $sources_small{$data{'package'}} .=
+ "$archive $suite $section $subsection $data{'priority'} $data{'version'}\000";
}
untie %sources_all_db;
+ }
+}
+
+print "Writing databases...\n";
+my %sources_small_db;
+tie %sources_small_db, "DB_File", "$DBDIR/sources_small.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+while (my ($k, $v) = each(%sources_small)) {
+ $v =~ s/.$//s;
+ $sources_small_db{$k} = $v;
+}
+untie %sources_small_db;
+
+# package names stuff:
+for my $pkg (keys %source_names) {
+ for (my $i=0;$i<length($pkg)-1;$i++) {
+ my $before = substr($pkg, 0, $i);
+ my $after = substr($pkg, $i);
+ $before = "^" if $before eq ""; # otherwise split doesn't work properly
+ $source_postfixes{$after} .= "$before\0";
+ }
+}
+my %source_postfixes_db;
+tie %source_postfixes_db, "DB_File", "$DBDIR/source_postfixes.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+while (my ($k, $v) = each(%source_postfixes)) {
+ $v =~ s/.$//s;
+ my $nr = $v;
+ $nr =~ s/[^\000]//g;
+ $nr = length($nr) + 1; # < number of hits
+ if ($nr > $MAX_SOURCE_POSTFIXES) {
+ $v = "\001" . $nr;
+ }
+ $source_postfixes_db{$k} = $v;
}
+untie %source_postfixes_db;
-for my $suite (@suites) {
- rename("sources_all_$suite.db.new", "sources_all_$suite.db");
+for my $suite (@SUITES) {
+ rename("$DBDIR/sources_all_$suite.db.new", "$DBDIR/sources_all_$suite.db");
}
+rename("$DBDIR/sources_small.db.new", "$DBDIR/sources_small.db");
+rename("$DBDIR/source_postfixes.db.new", "$DBDIR/source_postfixes.db");