]> git.donarmstrong.com Git - debbugs.git/commitdiff
[project @ 2000-04-29 10:57:20 by doogie]
authordoogie <>
Sat, 29 Apr 2000 17:57:21 +0000 (09:57 -0800)
committerdoogie <>
Sat, 29 Apr 2000 17:57:21 +0000 (09:57 -0800)
Added DBase::OpenRecord($record) and DBase::CloseRecord().  This should allow
for creating new records in this new framework.

Debbugs/DBase.pm
debbugs-dump

index 2a5fd0fd9bee848dab24f637fa9870b1f3c7fd30..cd37285b17b1f45e942ba9c69c3f5d2556d2bad2 100644 (file)
@@ -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)
index d562d60287fda64be9af4446d148bbdf9feeb1bc..cb5047e50b883e67cc3536d6d97ea28b18e3aa8d 100755 (executable)
@@ -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";
 }