1 # TODO: Implement 'stale' checks, so that there is no need to explicitly
2 # write out a record, before closing.
4 package Debbugs::DBase; # assumes Some/Module.pm
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 # set the version for version checking
16 @EXPORT = qw( %Record );
17 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
19 # your exported package globals go here,
20 # as well as any optionally exported functions
21 @EXPORT_OK = qw( %Record );
37 my $FileHandle = new FileHandle;
38 my $LogfileHandle = new FileHandle;
40 sub ParseVersion1Record
43 my @fields = ( "originator", "date", "subject", "msgid", "package",
44 "keywords", "done", "forwarded", "mergedwith", "severity" );
48 print "D2: (DBase) Record Fields:\n" if $Globals{ 'debug' } > 1;
49 foreach my $line ( @data )
53 $Record{ $tag } = $line;
54 print "\t $tag = $line\n" if $Globals{ 'debug' } > 1;
56 $GTags{ "BUG_$tag" } = $line;
60 sub ParseVersion2Record
62 # I envision the next round of records being totally different in
63 # meaning. In order to maintain compatability, version tagging will be
64 # implemented in thenext go around and different versions will be sent
65 # off to different functions to be parsed and interpreted into a format
66 # that the rest of the system will understand. All data will be saved
67 # in whatever 'new" format ixists. The difference will be a "Version: x"
68 # at the top of the file.
70 print "No version 2 records are understood at this time\n";
77 print "V: Reading status $record\n" if $Globals{ 'verbose' };
78 if ( $record ne $LoadedRecord )
82 seek( $FileHandle, 0, 0 );
83 @data = <$FileHandle>;
84 if ( scalar( @data ) =~ /Version: (\d*)/ )
87 { &ParseVersion2Record( @data ); }
89 { &fail( "Unknown record version: $1\n"); }
91 else { &ParseVersion1Record( @data ); }
92 $LoadedRecord = $record;
94 else { print "D1: (DBase) $record is already loaded\n" if $Globals{ 'debug' }; }
100 my @fields = ( "originator", "date", "subject", "msgid", "package",
101 "keywords", "done", "forwarded", "mergedwith", "severity" );
102 print "V: Writing status $LoadedRecord\n" if $Globals{ 'verbose' };
103 seek( $FileHandle, 0, 0 );
104 for( my $i = 0; $i < $#fields; $i++ )
106 if ( defined( $fields[$i] ) )
107 { print $FileHandle $Record{ $fields[$i] } . "\n"; }
108 else { print $FileHandle "\n"; }
114 my $prePath = $_[0], my $stub = $_[1], my $postPath = $_[2], my $desc = $_[3];
115 my $path = "/db/".$stub.".status", my $handle = new FileHandle;
116 print "V: Opening $desc $stub\n" if $Globals{ 'verbose' };
117 print "D2: (DBase) $path found as data path\n" if $Globals{ 'debug' } > 1;
118 if( ! -r $Globals{ "work-dir" } . $path ) {
120 $path = $prePath.Number2Path($stub).$postPath;
121 $dir = basename($path);
122 if( ! -d $Globals{ "work-dir" } . $dir ) {
123 print "D1 (DBase) making dir $dir\n" if $Globals{ 'debug' };
124 mkdir $Globals{ "work-dir" } . $dir, umask();
127 open( $handle, $Globals{ "work-dir" } . $path )
128 || &fail( "Unable to open $desc: ".$Globals{ "work-dir" }."$path\n");
134 if ( $record ne $OpenedRecord )
136 $FileHandle = OpenFile("/db/", $record, ".status", "status");
137 flock( $FileHandle, LOCK_EX ) || &fail( "Unable to lock record $record\n" );
138 $OpenedRecord = $record;
144 print "V: Closing status $LoadedRecord\n" if $Globals{ 'verbose' };
152 if ( $record ne $OpenedLog )
154 $LogfileHandle = OpenFile("/db/", $record, ".log", "log");
155 seek( $FileHandle, 0, 0 );
156 $OpenedLog = $record;
162 print "V: Closing log $OpenedLog\n" if $Globals{ 'verbose' };
163 close $LogfileHandle;
168 END { } # module clean-up code here (global destructor)