]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/common.pl
[project @ 2003-06-25 17:51:51 by cjwatson]
[debbugs.git] / cgi / common.pl
index 8c52ef706ed80731a6fc3376ea73cc34ca00a48e..ed9728e108d320f7614b12ea936836696e514e02 100644 (file)
@@ -2,12 +2,24 @@
 
 use DB_File;
 use Fcntl qw/O_RDONLY/;
+use Mail::Address;
+$config_path = '/etc/debbugs';
+$lib_path = '/usr/lib/debbugs';
+require "$lib_path/errorlib";
 
 my $common_archive = 0;
 my $common_repeatmerged = 1;
 my %common_include = ();
 my %common_exclude = ();
 my $common_raw_sort = 0;
+my $common_bug_reverse = 0;
+my $common_pending_reverse = 0;
+my $common_severity_reverse = 0;
+
+my @common_pending_include = ();
+my @common_pending_exclude = ();
+my @common_severity_include = ();
+my @common_severity_exclude = ();
 
 my $debug = 0;
 
@@ -15,9 +27,56 @@ sub set_option {
     my ($opt, $val) = @_;
     if ($opt eq "archive") { $common_archive = $val; }
     if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
-    if ($opt eq "exclude") { %common_exclude = %{$val}; }
-    if ($opt eq "include") { %common_include = %{$val}; }
+    if ($opt eq "exclude") {
+       my @vals;
+       @vals = ( $val ) if (ref($val) eq "" && $val );
+       @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       %common_exclude = map {
+           if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
+       } split /[\s,]+/, join ',', @vals;
+    }
+    if ($opt eq "include") {
+       my @vals;
+       @vals = ( $val, ) if (ref($val) eq "" && $val );
+       @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       %common_include = map {
+           if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
+       } split /[\s,]+/, join ',', @vals;
+    }
     if ($opt eq "raw") { $common_raw_sort = $val; }
+    if ($opt eq "bug-rev") { $common_bug_reverse = $val; }
+    if ($opt eq "pend-rev") { $common_pending_reverse = $val; }
+    if ($opt eq "sev-rev") { $common_severity_reverse = $val; }
+    if ($opt eq "pend-exc") {
+       my @vals;
+       @vals = ( $val ) if (ref($val) eq "" && $val );
+       @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       @common_pending_exclude = @vals if (@vals);
+    }
+    if ($opt eq "pend-inc") {
+       my @vals;
+       @vals = ( $val, ) if (ref($val) eq "" && $val );
+       @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       @common_pending_include = @vals if (@vals);
+    }
+    if ($opt eq "sev-exc") {
+       my @vals;
+       @vals = ( $val ) if (ref($val) eq "" && $val );
+       @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       @common_severity_exclude = @vals if (@vals);
+    }
+    if ($opt eq "sev-inc") {
+       my @vals;
+       @vals = ( $val ) if (ref($val) eq "" && $val );
+       @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
+       @vals = @{$val} if (ref($val) eq "ARRAY" );
+       @common_severity_include = @vals if (@vals);
+    }
 }
 
 sub readparse {
@@ -31,7 +90,7 @@ sub readparse {
     } else {
         return;
     }
-    foreach (split(/&/,$in)) {
+    foreach (split(/[&;]/,$in)) {
         s/\+/ /g;
         ($key, $val) = split(/=/,$_,2);
         $key=~s/%(..)/pack("c",hex($1))/ge;
@@ -48,7 +107,7 @@ $debug = 1 if (defined $ret{"debug"} && $ret{"debug"} eq "aj");
     return %ret;
 }
 
-sub quit {
+sub quitcgi {
     my $msg = shift;
     print "Content-Type: text/html\n\n";
     print "<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n";
@@ -67,6 +126,62 @@ sub quit {
 #    exit 0;
 #}
 
+# Split a package string from the status file into a list of package names.
+sub splitpackages {
+    my $pkgs = shift;
+    return unless defined $pkgs;
+    return map lc, split /[ \t?,()]+/, $pkgs;
+}
+
+my %_parsedaddrs;
+sub getparsedaddrs {
+    my $addr = shift;
+    return () unless defined $addr;
+    return @{$_parsedaddrs{$addr}} if exists $_parsedaddrs{$addr};
+    @{$_parsedaddrs{$addr}} = Mail::Address->parse($addr);
+    return @{$_parsedaddrs{$addr}};
+}
+
+# Generate a comma-separated list of HTML links to each package given in
+# $pkgs. $pkgs may be empty, in which case an empty string is returned, or
+# it may be a comma-separated list of package names.
+sub htmlpackagelinks {
+    my $pkgs = shift;
+    return unless defined $pkgs and $pkgs ne '';
+    my $strong = shift;
+    my @pkglist = splitpackages($pkgs);
+
+    my $openstrong  = $strong ? '<strong>' : '';
+    my $closestrong = $strong ? '</strong>' : '';
+
+    return 'Package' . (@pkglist > 1 ? 's' : '') . ': ' .
+           join(', ',
+                map {
+                    '<a href="' . pkgurl($_) . '">' .
+                    $openstrong . htmlsanit($_) . $closestrong . '</a>'
+                } @pkglist
+           ) . ";\n";
+}
+
+# Generate a comma-separated list of HTML links to each maintainer given in
+# $maints, which should be a comma-separated list of RFC822 addresses.
+sub htmlmaintlinks {
+    my ($prefixfunc, $maints) = @_;
+    if (defined $maints and $maints ne '') {
+        my @maintaddrs = getparsedaddrs($maints);
+        my $prefix = (ref $prefixfunc) ? $prefixfunc->(scalar @maintaddrs)
+                                       : $prefixfunc;
+        return $prefix .
+               join ', ', map { sprintf '<a href="%s">%s</a>',
+                                        mainturl($_->address),
+                                        htmlsanit($_->format) || '(unknown)'
+                              } @maintaddrs;
+    } else {
+        my $prefix = (ref $prefixfunc) ? $prefixfunc->(1) : $prefixfunc;
+        return sprintf '%s<a href="%s">(unknown)</a>', $prefix, mainturl('');
+    }
+}
+
 sub htmlindexentry {
     my $ref = shift;
     my %status = %{getbugstatus($ref)};
@@ -88,11 +203,10 @@ sub htmlindexentrystatus {
         $showseverity = "Severity: <em>$status{severity}</em>;\n";
     }
 
-    $result .= "Package: <a href=\"" . pkgurl($status{"package"}) . "\">"
-               . "<strong>" . htmlsanit($status{"package"}) . "</strong></a>;\n"
-               if (length($status{"package"}));
+    $result .= htmlpackagelinks($status{"package"}, 1);
     $result .= $showseverity;
-    $result .= "Reported by: " . htmlsanit($status{originator});
+    $result .= "Reported by: <a href=\"" . submitterurl($status{originator})
+               . "\">" . htmlsanit($status{originator}) . "</a>";
     $result .= ";\nTags: <strong>" 
                 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
                 . "</strong>"
@@ -107,10 +221,11 @@ sub htmlindexentrystatus {
 
     if (length($status{done})) {
         $result .= ";\n<strong>Done:</strong> " . htmlsanit($status{done});
-    } elsif (length($status{forwarded})) {
-        $result .= ";\n<strong>Forwarded</strong> to "
-                   . htmlsanit($status{forwarded});
     } else {
+        if (length($status{forwarded})) {
+            $result .= ";\n<strong>Forwarded</strong> to "
+                       . maybelink($status{forwarded});
+        }
         my $daysold = int((time - $status{date}) / 86400);   # seconds to days
         if ($daysold >= 7) {
             my $font = "";
@@ -120,15 +235,17 @@ sub htmlindexentrystatus {
             $efont = "</$font>" if ($font);
             $font = "<$font>" if ($font);
 
-            my $yearsold = int($daysold / 364);
-            $daysold = $daysold - $yearsold * 364;
+            my $yearsold = int($daysold / 365);
+            $daysold -= $yearsold * 365;
 
             $result .= ";\n $font";
-            $result .= "1 year and " if ($yearsold == 1);
-            $result .= "$yearsold years and " if ($yearsold > 1);
-            $result .= "1 day old" if ($daysold == 1);
-            $result .= "$daysold days old" if ($daysold != 1);
-            $result .= "$efont";
+            my @age;
+            push @age, "1 year" if ($yearsold == 1);
+            push @age, "$yearsold years" if ($yearsold > 1);
+            push @age, "1 day" if ($daysold == 1);
+            push @age, "$daysold days" if ($daysold > 1);
+            $result .= join(" and ", @age);
+            $result .= " old$efont";
         }
     }
 
@@ -141,59 +258,58 @@ sub submitterurl {
     my $ref = shift || "";
     my $params = "submitter=" . emailfromrfc822($ref);
     $params .= "&archive=yes" if ($common_archive);
-    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
-    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
+    $params .= "&repeatmerged=no" unless ($common_repeatmerged);
+    return urlsanit("pkgreport.cgi" . "?" . $params);
 }
 
 sub mainturl {
     my $ref = shift || "";
     my $params = "maint=" . emailfromrfc822($ref);
     $params .= "&archive=yes" if ($common_archive);
-    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
-    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
+    $params .= "&repeatmerged=no" unless ($common_repeatmerged);
+    return urlsanit("pkgreport.cgi" . "?" . $params);
 }
 
 sub pkgurl {
     my $ref = shift;
     my $params = "pkg=$ref";
     $params .= "&archive=yes" if ($common_archive);
-    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
+    $params .= "&repeatmerged=no" unless ($common_repeatmerged);
     
-    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . "$params");
+    return urlsanit("pkgreport.cgi" . "?" . "$params");
 }
 
 sub srcurl {
     my $ref = shift;
     my $params = "src=$ref";
     $params .= "&archive=yes" if ($common_archive);
-    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
-    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . "$params");
+    $params .= "&repeatmerged=no" unless ($common_repeatmerged);
+    return urlsanit("pkgreport.cgi" . "?" . "$params");
 }
 
 sub urlsanit {
     my $url = shift;
     $url =~ s/%/%25/g;
     $url =~ s/\+/%2b/g;
-    my %saniarray = ('<','lt', '>','gt', '"','quot');
-    my $out;
-    while ($url =~ m/[<>"]/) {
-        $out .= $`. '&'. $saniarray{$&}. ';';
-        $url = $';
-    }
-    $out .= $url;
-    return $out;
+    my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
+    $url =~ s/([<>&"])/\&$saniarray{$1};/g;
+    return $url;
 }
 
 sub htmlsanit {
     my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
     my $in = shift || "";
-    my $out;
-    while ($in =~ m/[<>&"]/) {
-        $out .= $`. '&'. $saniarray{$&}. ';';
-        $in = $';
+    $in =~ s/([<>&"])/\&$saniarray{$1};/g;
+    return $in;
+}
+
+sub maybelink {
+    my $in = shift;
+    if ($in =~ /^[a-zA-Z0-9+.-]+:/) { # RFC 1738 scheme
+       return qq{<a href="$in">} . htmlsanit($in) . '</a>';
+    } else {
+       return htmlsanit($in);
     }
-    $out .= $in;
-    return $out;
 }
 
 sub bugurl {
@@ -204,26 +320,33 @@ sub bugurl {
        $params .= "\&archive=yes" if (!$common_archive && $val =~ /^archive.*$/);
     }
     $params .= "&archive=yes" if ($common_archive);
-    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
+    $params .= "&repeatmerged=no" unless ($common_repeatmerged);
 
-    return urlsanit($debbugs::gCGIDomain . "bugreport.cgi" . "?" . "$params");
+    return urlsanit("bugreport.cgi" . "?" . "$params");
 }
 
-sub packageurl {
+sub dlurl {
     my $ref = shift;
-    return urlsanit($debbugs::gCGIDomain . "package.cgi" . "?" . "package=$ref");
-}
+    my $params = "bug=$ref";
+    my $filename = '';
+    foreach my $val (@_) {
+       $params .= "\&$1=$2" if ($val =~ /^(msg|att)=([0-9]+)/);
+       $filename = $1 if ($val =~ /^filename=(.*)$/);
+    }
+    $params .= "&archive=yes" if ($common_archive);
+    my $pathinfo = '';
+    $pathinfo = "/$filename" if $filename ne '';
 
-sub allbugs {
-    my @bugs = ();
+    return urlsanit("bugreport.cgi$pathinfo?$params");
+}
 
-    opendir(D, "$debbugs::gSpoolDir/db") or &quit("opendir db: $!");
-    @bugs = sort {$a<=>$b} grep s/\.status$//,
-                (grep m/^[0-9]+\.status$/,
-                (readdir(D)));
-    closedir(D);
+sub mboxurl {
+    my $ref = shift;
+    return urlsanit("bugreport.cgi" . "?" . "bug=$ref&mbox=yes");
+}
 
-    return @bugs;
+sub allbugs {
+    return @{getbugs(sub { 1 })};
 }
 
 sub htmlizebugs {
@@ -243,11 +366,15 @@ sub htmlizebugs {
         return "<HR><H2>No reports found!</H2></HR>\n";
     }
 
-    foreach my $bug (sort {$a<=>$b} @bugs) {
+    if ( $common_bug_reverse ) {
+       @bugs = sort {$b<=>$a} @bugs;
+    } else {
+       @bugs = sort {$a<=>$b} @bugs;
+    }
+    my %seenmerged;
+    foreach my $bug (@bugs) {
        my %status = %{getbugstatus($bug)};
         next unless %status;
-       my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
-       next unless ($common_repeatmerged || $bug == $merged[0]);
        if (%common_include) {
            my $okay = 0;
            foreach my $t (split /\s+/, $status{tags}) {
@@ -272,7 +399,17 @@ sub htmlizebugs {
             }
            next unless ($okay);
        }
-           
+       next if @common_pending_include and
+            not grep { $_ eq $status{pending} } @common_pending_include;
+       next if @common_severity_include and
+            not grep { $_ eq $status{severity} } @common_severity_include;
+       next if grep { $_ eq $status{pending} } @common_pending_exclude;
+       next if grep { $_ eq $status{severity} } @common_severity_exclude;
+
+       my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
+       next unless ($common_repeatmerged || !$seenmerged{$merged[0]});
+       $seenmerged{$merged[0]} = 1;
+
        my $html = sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
            bugurl($bug), $bug, htmlsanit($status{subject});
        $html .= htmlindexentrystatus(\%status) . "\n";
@@ -285,13 +422,22 @@ sub htmlizebugs {
     if ($common_raw_sort) {
        $result .= "<UL>\n" . join("", @rawsort ) . "</UL>\n";
     } else {
-    foreach my $pending (qw(pending forwarded pending-fixed fixed done)) {
-        foreach my $severity(@debbugs::gSeverityList) {
+       my @pendingList = qw(pending forwarded pending-fixed fixed done);
+       @pendingList = reverse @pendingList if $common_pending_reverse;
+#print STDERR join(",",@pendingList)."\n";
+#print STDERR join(",",@common_pending_include).":$#common_pending_include\n";
+    foreach my $pending (@pendingList) {
+       my @severityList = @debbugs::gSeverityList;
+       @severityList = reverse @severityList if $common_severity_reverse;
+#print STDERR join(",",@severityList)."\n";
+
+#        foreach my $severity(@debbugs::gSeverityList) {
+        foreach my $severity(@severityList) {
             $severity = $debbugs::gDefaultSeverity if ($severity eq '');
             next unless defined $section{${pending} . "_" . ${severity}};
             $result .= "<HR><H2>$debbugs::gSeverityDisplay{$severity} - $displayshowpending{$pending}</H2>\n";
             #$result .= "(A list of <a href=\"http://${debbugs::gWebDomain}/db/si/$pending$severity\">all such bugs</a> is available).\n";
-           $result .= "(A list of all such bugs used to be available).\n";
+            #$result .= "(A list of all such bugs used to be available).\n";
             $result .= "<UL>\n";
            $result .= $section{$pending . "_" . $severity}; 
            $result .= "</UL>\n";
@@ -307,18 +453,21 @@ sub htmlizebugs {
 sub countbugs {
     my $bugfunc = shift;
     if ($common_archive) {
-        open I, "<$debbugs::gSpoolDir/index.archive" or &quit("bugindex: $!");
+        open I, "<$debbugs::gSpoolDir/index.archive"
+            or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
     } else {
-        open I, "<$debbugs::gSpoolDir/index.db" or &quit("bugindex: $!");
+        open I, "<$debbugs::gSpoolDir/index.db"
+            or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
     }
 
     my %count = ();
     while(<I>) 
     {
         if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
-            my $x = $bugfunc->(pkg => $1, bug => $2, status => $4, 
+            my @x = $bugfunc->(pkg => $1, bug => $2, status => $4, 
                                submitter => $5, severity => $6, tags => $7);
-           $count{$x}++;
+            local $_;
+            $count{$_}++ foreach @x;
        }
     }
     close I;
@@ -349,10 +498,10 @@ print STDERR "done optimized\n" if ($debug);
     } else {
         if ( $common_archive ) {
             open I, "<$debbugs::gSpoolDir/index.archive" 
-                or &quit("bugindex: $!");
+                or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
         } else {
             open I, "<$debbugs::gSpoolDir/index.db" 
-                or &quit("bugindex: $!");
+                or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
         }
         while(<I>) {
             if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
@@ -399,7 +548,7 @@ sub getmaintainers {
     return $_maintainer if $_maintainer;
     my %maintainer;
 
-    open(MM,"$gMaintainerFile") or &quit("open $gMaintainerFile: $!");
+    open(MM,"$gMaintainerFile") or &quitcgi("open $gMaintainerFile: $!");
     while(<MM>) {
        next unless m/^(\S+)\s+(\S.*\S)\s*$/;
        ($a,$b)=($1,$2);
@@ -407,60 +556,73 @@ sub getmaintainers {
        $maintainer{$a}= $b;
     }
     close(MM);
-    open(MM,"$gMaintainerFileOverride") or &quit("open $gMaintainerFileOverride: $!");
-    while(<MM>) {
-       next unless m/^(\S+)\s+(\S.*\S)\s*$/;
-       ($a,$b)=($1,$2);
-       $a =~ y/A-Z/a-z/;
-       $maintainer{$a}= $b;
+    if (defined $gMaintainerFileOverride) {
+       open(MM,"$gMaintainerFileOverride") or &quitcgi("open $gMaintainerFileOverride: $!");
+       while(<MM>) {
+           next unless m/^(\S+)\s+(\S.*\S)\s*$/;
+           ($a,$b)=($1,$2);
+           $a =~ y/A-Z/a-z/;
+           $maintainer{$a}= $b;
+       }
+       close(MM);
     }
-    close(MM);
     $_maintainer = \%maintainer;
     return $_maintainer;
 }
 
 my $_pkgsrc;
+my $_pkgcomponent;
 sub getpkgsrc {
     return $_pkgsrc if $_pkgsrc;
+    return {} unless defined $gPackageSource;
     my %pkgsrc;
+    my %pkgcomponent;
 
-    open(MM,"$gPackageSource") or &quit("open $gPackageSource: $!");
+    open(MM,"$gPackageSource") or &quitcgi("open $gPackageSource: $!");
     while(<MM>) {
-       next unless m/^(\S+)\s+(\S.*\S)\s*$/;
-       ($a,$b)=($1,$2);
+       next unless m/^(\S+)\s+(\S+)\s+(\S.*\S)\s*$/;
+       ($a,$b,$c)=($1,$2,$3);
        $a =~ y/A-Z/a-z/;
-       $pkgsrc{$a}= $b;
+       $pkgsrc{$a}= $c;
+       $pkgcomponent{$a}= $b;
     }
     close(MM);
     $_pkgsrc = \%pkgsrc;
+    $_pkgcomponent = \%pkgcomponent;
     return $_pkgsrc;
 }
 
-sub getbugdir {
-    my ( $bugnum, $ext ) = @_;
-    my $archdir = sprintf "%02d", $bugnum % 100;
-    foreach ( ( "$gSpoolDir/db-h/$archdir", "$gSpoolDir/db", "$gSpoolDir/archive/$archdir" ) ) {
-       return $_ if ( -r "$_/$bugnum.$ext" );
+sub getpkgcomponent {
+    return $_pkgcomponent if $_pkgcomponent;
+    getpkgsrc();
+    return $_pkgcomponent;
+}
+
+my $_pseudodesc;
+sub getpseudodesc {
+    return $_pseudodesc if $_pseudodesc;
+    my %pseudodesc;
+
+    open(PSEUDO, "< $gPseudoDescFile") or &quitcgi("open $gPseudoDescFile: $!");
+    while(<PSEUDO>) {
+       next unless m/^(\S+)\s+(\S.*\S)\s*$/;
+       $pseudodesc{lc $1} = $2;
     }
-    return undef;
+    close(PSEUDO);
+    $_pseudodesc = \%pseudodesc;
+    return $_pseudodesc;
 }
-    
+
 sub getbugstatus {
     my $bugnum = shift;
 
     my %status;
 
-    my $dir = getbugdir( $bugnum, "status" );
-    return {} if ( !$dir );
-    open S, "< $dir/$bugnum.status";
-    my @lines = qw(originator date subject msgid package tags done
-                       forwarded mergedwith severity);
-    while(<S>) {
-        chomp;
-       $status{shift @lines} = $_;
-    }
-    close(S);
-    $status{shift @lines} = '' while(@lines);
+    my $location = getbuglocation( $bugnum, "status" );
+    return {} if ( !$location );
+    %status = %{ readbug( $bugnum, $location ) };
+
+    $status{tags} = $status{keywords};
 
     $status{"package"} =~ s/\s*$//;
     $status{"package"} = 'unknown' if ($status{"package"} eq '');
@@ -468,8 +630,8 @@ sub getbugstatus {
 
     $status{"pending"} = 'pending';
     $status{"pending"} = 'forwarded'       if (length($status{"forwarded"}));
-    $status{"pending"} = 'fixed'           if ($status{"tags"} =~ /\bfixed\b/);
     $status{"pending"} = 'pending-fixed'    if ($status{"tags"} =~ /\bpending\b/);
+    $status{"pending"} = 'fixed'           if ($status{"tags"} =~ /\bfixed\b/);
     $status{"pending"} = 'done'                    if (length($status{"done"}));
 
     return \%status;
@@ -477,7 +639,7 @@ sub getbugstatus {
 
 sub getsrcpkgs {
     my $src = shift;
-
+    return () if !$src;
     my %pkgsrc = %{getpkgsrc()};
     my @pkgs;
     foreach ( keys %pkgsrc ) {
@@ -488,10 +650,8 @@ sub getsrcpkgs {
    
 sub buglog {
     my $bugnum = shift;
-
-    my $dir = getbugdir( $bugnum, "log" );
-    return "" if ( !$dir );
-    return "$dir/$bugnum.log";
+    my $location = getbuglocation($bugnum, 'log');
+    return getbugcomponent($bugnum, 'log', $location);
 }
 
 1;