2 # Convert Contents.gz files into Sleepycat db files for efficient usage of
7 # Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
28 &Packages::Config::init( './' );
29 my %packages_contents = ();
30 my %file_reverse = ();
32 my @archives =( 'us'); #@ARCHIVES
33 my @suites = ('stable');#@SUITES
35 for my $archive (@archives) { for my $suite (@suites) {
37 print "Reading $archive/$suite/i386...\n";
38 open CONT, "zcat /org/ftp.debian.org/ftp/dists/stable/Contents-i386.gz|";
39 while (1) {$_ = <CONT>;last if /^FILE/mo;}
44 print "Doing line $.\n" if $. % 10000 == 0;
46 my ($file, $value) = ($1, $2);
47 $value =~ s#[^,/]+/##g;
48 my @packages = split /,/, $value;
50 #$packages_contents{$_} .= "$_\0";
52 # Searches are case-insensitive
53 $file =~ tr [A-Z] [a-z];
55 $file_reverse{reverse $file} = join "\0", @packages;
59 print "Writing databases...\n";
60 my %packages_contents_db;
61 tie %packages_contents_db, "DB_File", "packages_contents.db.new",
62 O_RDWR|O_CREAT, 0666, $DB_BTREE
63 or die "Error creating DB: $!";
64 while (my ($k, $v) = each(%packages_contents)) {
66 $packages_contents_db{$k} = $v;
68 untie %packages_contents_db;
71 tie %file_reverse_db, "DB_File", "$DBDIR/file_reverse.db.new",
72 O_RDWR|O_CREAT, 0666, $DB_BTREE
73 or die "Error creating DB: $!";
74 while (my ($x, $y) = each(%file_reverse)) {
77 # $nr =~ s/[^\000]//g;
78 # $nr = length($nr) + 1; # < number of hits
79 # if ($nr > $MAX_file_reverse) {
82 $file_reverse_db{$x} = $y;
84 untie %file_reverse_db;
86 #rename("packages_contents.db.new", "packages_contents.db");
87 rename("$DBDIR/file_reverse.db.new", "$DBDIR/file_reverse.db");