+# 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;
%Record = ();
my $LoadedRecord = 0;
+my $OpenedRecord = 0;
my $FileLocked = 0;
my $FileHandle = new FileHandle;
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*)/ )
{
{ 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)
#!/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);
"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 );
## 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";
}