-sub read_entry {
- my ($hash, $key, $results, $opts) = @_;
- my $result = $hash->{$key} || '';
- foreach (split /\000/, $result) {
- my @data = split ( /\s/, $_, 7 );
- debug( "Considering entry ".join( ':', @data), 2);
- if ($opts->{h_suites}{$data[0]}
- && ($opts->{h_archs}{$data[1]} || $data[1] eq 'all')
- && $opts->{h_sections}{$data[2]}) {
- debug( "Using entry ".join( ':', @data), 2);
- push @$results, [ $key, @data ];
- }
- }
-}
-sub read_src_entry {
- my ($hash, $key, $results, $opts) = @_;
- my $result = $hash->{$key} || '';
- foreach (split /\000/, $result) {
- my @data = split ( /\s/, $_, 5 );
- debug( "Considering entry ".join( ':', @data), 2);
- if ($opts->{h_suites}{$data[0]} && $opts->{h_sections}{$data[1]}) {
- debug( "Using entry ".join( ':', @data), 2);
- push @$results, [ $key, @data ];
- }
- }
-}
-sub do_names_search {
- my ($keyword, $file, $postfix_file, $read_entry, $opts) = @_;
- my @results;
-
- $keyword = lc $keyword unless $opts->{case_bool};
-
- my $obj = tie my %packages, 'DB_File', "$DBDIR/$file", O_RDONLY, 0666, $DB_BTREE
- or die "couldn't tie DB $DBDIR/$file: $!";
-
- if ($opts->{exact}) {
- &$read_entry( \%packages, $keyword, \@results, $opts );
- } else {
- my ($key, $prefixes) = ($keyword, '');
- my %pkgs;
- my $p_obj = tie my %pref, 'DB_File', "$DBDIR/$postfix_file", O_RDONLY, 0666, $DB_BTREE
- or die "couldn't tie postfix db $DBDIR/$postfix_file: $!";
- $p_obj->seq( $key, $prefixes, R_CURSOR );
- while (index($key, $keyword) >= 0) {
- if ($prefixes =~ /^\001(\d+)/o) {
- $too_many_hits += $1;
- } else {
- foreach (split /\000/o, $prefixes) {
- $_ = '' if $_ eq '^';
- debug( "add word $_$key", 2);
- $pkgs{$_.$key}++;
- }
- }
- last if $p_obj->seq( $key, $prefixes, R_NEXT ) != 0;
- last if $too_many_hits or keys %pkgs >= 100;
- }
-
- my $no_results = keys %pkgs;
- if ($too_many_hits || ($no_results >= 100)) {
- $too_many_hits += $no_results;
- %pkgs = ( $keyword => 1 );
- }
- foreach my $pkg (sort keys %pkgs) {
- &$read_entry( \%packages, $pkg, \@results, $opts );
- }
- }
- return \@results;
-}
-sub do_fulltext_search {
- my ($keword, $file, $mapping, $lookup, $read_entry, $opts) = @_;
- my @results;
-
- my @lines;
- my $regex;
- if ($opts->{case_bool}) {
- if ($opts->{exact}) {
- $regex = qr/\b\Q$keyword\E\b/o;
- } else {
- $regex = qr/\Q$keyword\E/o;
- }
- } else {
- if ($opts->{exact}) {
- $regex = qr/\b\Q$keyword\E\b/io;
- } else {
- $regex = qr/\Q$keyword\E/io;
- }
- }
-
- open DESC, '<', "$DBDIR/$file"
- or die "couldn't open $DBDIR/$file: $!";
- while (<DESC>) {
- $_ =~ $regex or next;
- debug( "Matched line $.", 2);
- push @lines, $.;
- }
- close DESC;
-
- tie my %packages, 'DB_File', "$DBDIR/$lookup", O_RDONLY, 0666, $DB_BTREE
- or die "couldn't tie DB $DBDIR/$lookup: $!";
- tie my %did2pkg, 'DB_File', "$DBDIR/$mapping", O_RDONLY, 0666, $DB_BTREE
- or die "couldn't tie DB $DBDIR/$mapping: $!";
-
- my %tmp_results;
- foreach my $l (@lines) {
- my $result = $did2pkg{$l};
- foreach (split /\000/o, $result) {
- my @data = split /\s/, $_, 3;
- next unless $opts->{h_archs}{$data[2]};
- $tmp_results{$data[0]}++;
- }
- }
- foreach my $pkg (keys %tmp_results) {
- &$read_entry( \%packages, $pkg, \@results, $opts );
+our ($obj, $s_obj, $p_obj, $sp_obj,
+ %packages, %sources, %postf, %spostf, %src2bin, %did2pkg );
+
+unless (@Packages::CGI::fatal_errors) {
+
+ my $dbmodtime = (stat("$DBDIR/packages_small.db"))[9];
+ if ($dbmodtime > $db_read_time) {
+ $obj = tie %packages, 'DB_File', "$DBDIR/packages_small.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie DB $DBDIR/packages_small.db: $!";
+ $s_obj = tie %sources, 'DB_File', "$DBDIR/sources_small.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie DB $DBDIR/sources_small.db: $!";
+ $p_obj = tie %postf, 'DB_File', "$DBDIR/package_postfixes.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie postfix db $DBDIR/package_postfixes.db: $!";
+ $sp_obj = tie %spostf, 'DB_File', "$DBDIR/source_postfixes.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie postfix db $DBDIR/source_postfixes.db: $!";
+ tie %src2bin, 'DB_File', "$DBDIR/sources_packages.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't open $DBDIR/sources_packages.db: $!";
+ tie %did2pkg, 'DB_File', "$DBDIR/descriptions_packages.db",
+ O_RDONLY, 0666, $DB_BTREE
+ or die "couldn't tie DB $DBDIR/descriptions_packages.db: $!";
+
+ debug( "tied databases ($dbmodtime > $db_read_time)" );
+ $db_read_time = $dbmodtime;