From: doogie <> Date: Sat, 29 Apr 2000 17:57:21 +0000 (-0800) Subject: [project @ 2000-04-29 10:57:20 by doogie] X-Git-Tag: release/2.6.0~1303 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9ca7bd6014e7a7c77285f8e67d8d6dc80af8a2aa;p=debbugs.git [project @ 2000-04-29 10:57:20 by doogie] Added DBase::OpenRecord($record) and DBase::CloseRecord(). This should allow for creating new records in this new framework. --- diff --git a/Debbugs/DBase.pm b/Debbugs/DBase.pm index 2a5fd0fd..cd37285b 100644 --- a/Debbugs/DBase.pm +++ b/Debbugs/DBase.pm @@ -1,3 +1,6 @@ +# TODO: Implement 'stale' checks, so that there is no need to explicitly +# write out a record, before closing. + package Debbugs::DBase; # assumes Some/Module.pm use strict; @@ -28,6 +31,7 @@ use FileHandle; %Record = (); my $LoadedRecord = 0; +my $OpenedRecord = 0; my $FileLocked = 0; my $FileHandle = new FileHandle; @@ -71,20 +75,9 @@ sub ReadRecord print "V: Reading $record\n" if $Globals{ 'verbose' }; if ( $record ne $LoadedRecord ) { - my $path = ''; my @data; - print "D1: (DBase) $record is being loaded\n" if $Globals{ 'debug' }; - - $path = "/db/".$record.".status"; - if( ! -r $Globals{ "work-dir" } . $path ) { - $path = "/db/".&NameToPathHash($record).".status"; - } - print "D2: (DBase) $path found as data path\n" if $Globals{ 'debug' } > 1; - - open( $FileHandle, $Globals{ "work-dir" } . $path ) - || &fail( "Unable to open record: ".$Globals{ "work-dir" }."$path\n"); - flock( $FileHandle, LOCK_EX ) || &fail( "Unable to lock record $record\n" ); + seek( $FileHandle, 0, 0 ); @data = <$FileHandle>; if ( scalar( @data ) =~ /Version: (\d*)/ ) { @@ -111,10 +104,41 @@ sub WriteRecord { print $FileHandle $Record{ $fields[$i] } . "\n"; } else { print $FileHandle "\n"; } } - close $FileHandle; $LoadedRecord = 0; } +sub OpenRecord +{ + my $record = $_[0]; + if ( $record ne $OpenedRecord ) + { + my $path; + print "V: Opening $record\n" if $Globals{ 'verbose' }; + $path = "/db/".$record.".status"; + print "D2: (DBase) $path found as data path\n" if $Globals{ 'debug' } > 1; + if( ! -r $Globals{ "work-dir" } . $path ) { + my $dir; + $path = "/db/".Number2Path($record).".status"; + $dir = basename($path); + if( ! -d $dir ) { + print "D1 (DBase) making dir $dir\n" if $Globals{ 'debug' }; + mkdir $dir, umask(); + } + } + open( $FileHandle, $Globals{ "work-dir" } . $path ) + || &fail( "Unable to open record: ".$Globals{ "work-dir" }."$path\n"); + flock( $FileHandle, LOCK_EX ) || &fail( "Unable to lock record $record\n" ); + $OpenedRecord = $record; + } +} + +sub CloseRecord +{ + print "V: Closing $LoadedRecord\n" if $Globals{ 'verbose' }; + close $FileHandle; + $OpenedRecord = 0; +} + 1; END { } # module clean-up code here (global destructor) diff --git a/debbugs-dump b/debbugs-dump index d562d602..cb5047e5 100755 --- a/debbugs-dump +++ b/debbugs-dump @@ -1,6 +1,7 @@ #!/usr/bin/perl -w push(@INC,'/home/gecko/debian/debvote'); +push(@INC,'/debian/home/doogie/debian/debbugs/cvs'); use strict; use Debbugs::Config qw(%Globals &ParseConfigFile); #use Debvote::Email qw(&InitEmailTags &LoadEmail &ProcessTags %gtags); @@ -33,7 +34,7 @@ my %opthash = (# ------------------ actions "version|V" => \&banner, "verbose|v!" => \$verbose, "quiet|q!" => \$quiet, - "debug|d+" => \$debug, # Count the -d flags + "debug|d" => \$debug, # Count the -d flags ); Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev'); GetOptions(%opthash) or &syntax( 1 ); @@ -57,15 +58,19 @@ print "D1: config file=$config\n" if $Globals{ 'debug' }; ## Put Real Code Here -Debbugs::DBase::ReadRecord( "59999" ); +Debbugs::DBase::OpenRecord( "59998" ); +Debbugs::DBase::ReadRecord( "59998" ); +Debbugs::DBase::CloseRecord(); foreach my $key ( keys( %Record ) ) { - # print "Key= $key Value = ". $Record{ "$key" } . "\n"; + print "Key= $key Value = ". $Record{ "$key" } . "\n"; } -Debbugs::DBase::ReadRecord( "60000" ); +Debbugs::DBase::OpenRecord( "60003" ); +Debbugs::DBase::ReadRecord( "60003" ); +Debbugs::DBase::CloseRecord(); foreach my $key ( keys( %Record ) ) { -# print "Key= $key Value = ". $Record{ "$key" } . "\n"; + print "Key= $key Value = ". $Record{ "$key" } . "\n"; }