From d0e554d25adfe94a2d5a1c3f57b48bfab1a9f4a2 Mon Sep 17 00:00:00 2001 From: minima Date: Sun, 13 Oct 2002 11:58:01 +0000 Subject: [PATCH] fixed basic usdb stuff --- cmd/load/usdb.pl | 6 ++++-- perl/USDB.pm | 32 +++++++++++++++++++++++--------- perl/cluster.pl | 3 ++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/cmd/load/usdb.pl b/cmd/load/usdb.pl index 2ca209a3..7ed76067 100644 --- a/cmd/load/usdb.pl +++ b/cmd/load/usdb.pl @@ -12,9 +12,11 @@ # $Id$ # -my $self = shift; +my ($self, $line) = @_; my @out; return (1, $self->msg('e5')) if $self->priv < 9; -push @out, (USDB::load()); +return (1, $self->msg('e3', "load/usdb", $line)) if $line && !-r $line; +$line = "$main::data/usdbraw" unless $line; +push @out, (USDB::load($line)); @out = ($self->msg('ok')) unless @out; return (1, @out); diff --git a/perl/USDB.pm b/perl/USDB.pm index 3b62fa5d..ed519b4b 100644 --- a/perl/USDB.pm +++ b/perl/USDB.pm @@ -5,6 +5,8 @@ # # +package USDB; + use strict; use DXVars; @@ -19,9 +21,9 @@ $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)) $main::build += $VERSION; $main::branch += $BRANCH; -use vars qw(%db $present); +use vars qw(%db $present $dbfn); -my $dbfn = "$main::data/usdb.v1"; +$dbfn = "$main::data/usdb.v1"; sub init { @@ -64,17 +66,28 @@ sub getcity # # Note that this removes and overwrites the existing DB file # You will need to init again after doing this -# +# sub load { + return "Need a filename" unless @_; + # create the new output file my $a = new DB_File::BTREEINFO; $a->{psize} = 4096 * 2; - my $s; - if ($s = -s $dbfn && $s > 1024 * 1024) { - $a->{cachesize} = int(($s / (1024*1024)) / 2) * 1024 * 1024; + my $s = 0; + + # guess a cache size + for (@_) { + my $ts = -s; + $s = $ts if $ts > $s; + } + if ($s > 1024 * 1024) { + $a->{cachesize} = int($s / (1024*1024)) * 3 * 1024 * 1024; } + +# print "cache size " . $a->{cachesize} . "\n"; + my %dbn; if (-e $dbfn ) { syscopy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!"; @@ -86,9 +99,10 @@ sub load for (@_) { my $fn = shift; my $f = gzopen($fn, "r") or return "Cannot open $fn $!"; - while ($f->gzreadline) { - chomp; - my ($call, $city, $state) = split /\|/; + my $l; + while ($f->gzreadline($l)) { + chomp $l; + my ($call, $city, $state) = split /\|/, $l; # lookup the city my $s = "$city|$state"; diff --git a/perl/cluster.pl b/perl/cluster.pl index f1cf1227..04a845d6 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -96,6 +96,7 @@ use Route::Node; use Route::User; use Editable; use Mrtg; +use USDB; use Data::Dumper; use IO::File; @@ -123,7 +124,7 @@ $reqreg = 0; # 1 = registration required, 2 = deregister people use vars qw($VERSION $BRANCH $build $branch); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += 8; # add an offset to make it bigger than last system +$main::build += 7; # add an offset to make it bigger than last system $main::build += $VERSION; $main::branch += $BRANCH; -- 2.43.0