+ if (!&lockreadbug($lref, $location)) { &unfilelock; return ( 0, undef ); }
+ return ( 2, $data );
+}
+
+sub getbuglocation {
+ my ( $bugnum, $ext ) = @_;
+ my $archdir = sprintf "%02d", $bugnum % 100;
+ return 'archive' if ( -r "$gSpoolDir/archive/$archdir/$bugnum.$ext" );
+ return 'db-h' if ( -r "$gSpoolDir/db-h/$archdir/$bugnum.$ext" );
+ return 'db' if ( -r "$gSpoolDir/db/$bugnum.$ext" );
+ return undef;
+}
+
+sub getlocationpath {
+ my ($location) = @_;
+ if ($location eq 'archive') {
+ return "$gSpoolDir/archive";
+ } elsif ($location eq 'db') {
+ return "$gSpoolDir/db";
+ } else {
+ return "$gSpoolDir/db-h";
+ }
+}
+
+sub getbugcomponent {
+ my ($bugnum, $ext, $location) = @_;
+
+ $location = getbuglocation($bugnum, $ext) unless defined $location;
+ my $dir = getlocationpath($location);
+ return undef unless $dir;
+ if ($location eq 'db') {
+ return "$dir/$bugnum.$ext";
+ } else {
+ my $hash = get_hashname($bugnum);
+ return "$dir/$hash/$bugnum.$ext";
+ }
+}
+
+sub readbug {
+ local ($lref, $location) = @_;
+ my $status = getbugcomponent($lref, 'status', $location);
+ return undef unless defined $status;
+ if (!open(S,$status)) { return undef; }
+ my %data;
+ chop($data{originator}= <S>);
+ chop($data{date}= <S>);
+ chop($data{subject}= <S>);
+ chop($data{msgid}= <S>);
+ chop($data{package}= <S>);
+ chop($data{keywords}= <S>);
+ chop($data{done}= <S>);
+ chop($data{forwarded}= <S>);
+ chop($data{mergedwith}= <S>);
+ chop($data{severity}= <S>);
+ chop($data{versions}= <S>);
+ chop($data{fixed_versions}= <S>);
+ close(S);
+ $data{severity} = 'normal' if $data{severity} eq '';
+ return \%data;