# Convert Sources.gz files into Sleepycat db files for efficient usage of
# data
#
-# $Id$
-#
# Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use lib './lib';
my $MAX_SOURCE_POSTFIXES = 100;
use DB_File;
+use File::Path;
use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
&Packages::Config::init( './' );
my %sources_small = ();
$/ = "";
+-d $DBDIR || mkpath( $DBDIR );
+
for my $archive (@ARCHIVES) {
for my $suite (@SUITES) {
tie %sources_all_db, "DB_File", "$DBDIR/sources_all_$suite.db.new",
O_RDWR|O_CREAT, 0666, $DB_BTREE
or die "Error creating DB: $!";
+ if (!-d "$TOPDIR/archive/$archive/$suite/") {
+ print "\tseems not to exist, skipping...\n";
+ next;
+ }
open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/source/Sources.gz|";
while (<PKG>) {
next if /^\s*$/;
my $subsection = $data{section} || '-';
if ($data{section} && ($data{section} =~ m=/=o)) {
($section, $subsection) = split m=/=o, $data{section}, 2;
- ($subsection, $section) = split m=/=o, $data{section}, 2
- if $section eq 'non-US';
}
$data{'section'} = $section;
$data{'subsection'} = $subsection;
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
+ my $nr = ($v =~ tr/\000/\000/) + 1;
if ($nr > $MAX_SOURCE_POSTFIXES) {
- $v = "\001" . $nr;
+ $v = ($v =~ /\^/) ? "^\001" . $nr
+ : "\001" . $nr;
}
$source_postfixes_db{$k} = $v;
}