]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/local-debbugs
add bugs listed in the config file to the mirrored bugs
[debbugs.git] / bin / local-debbugs
index 6df4b15a2522a39af8a9fa97a28f419a0538f120..1f212436f9c294fa28056224fbb8098d9e740f84 100755 (executable)
@@ -183,6 +183,24 @@ if ($options{daemon}) {
          print STDERR "Unable to determine if daemon is running: $!\n";
          exit 1;
      }
+     my $conf = IO::File->new($options{mirror_location}.'/debbugs_config_local','w') or
+        die "Unable to open $options{mirror_location}/debbugs_config_local for writing: $!";
+     print {$conf} <<"EOF";
+\$gConfigDir = "$options{mirror_location}";
+\$gSpoolDir = "$options{mirror_location}";
+\$gWebHost = 'localhost:$options{port}';
+\$gPackageSource = '';
+\$gPseudoDescFile = '';
+\$gPseudoMaintFile = '';
+\$gMaintainerFile = '';
+\$gMaintainerFileOverride = '';
+\$config{source_maintainer_file} = '';
+\$config{source_maintainer_file_override} = '';
+\$gProject = 'Local Debbugs';
+1;
+EOF
+     close $conf;
+     $ENV{DEBBUGS_CONFIG_FILE} = $options{mirror_location}.'/debbugs_config_local';
      # ok, now lets daemonize
 
      # XXX make sure that all paths have been turned into absolute
@@ -206,7 +224,7 @@ if ($options{daemon}) {
          package local_debbugs::server;
          use IO::File;
          use HTTP::Server::Simple;
-         use base qw(HTTP::Server::Simple::CGI);
+         use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment);
 
          sub net_server {
               return 'Net::Server::Fork';
@@ -222,6 +240,7 @@ if ($options{daemon}) {
          sub handle_request {
               my ($self,$cgi) = @_;
 
+              $ENV{DEBBUGS_CONFIG_FILE} = $options{mirror_location}.'/debbugs_config_local';
               my $base_uri = 'http://'.$cgi->virtual_host;
               if ($cgi->virtual_port ne 80) {
                    $base_uri .= ':'.$cgi->virtual_port;
@@ -261,10 +280,28 @@ if ($options{daemon}) {
               }
               elsif ($path =~ m{^/?cgi(?:-bin)?/((?:(?:bug|pkg)report|version)\.cgi)}) {
                    # dispatch to pkgreport.cgi
-                   print "HTTP/1.1 200 OK\n";
-                   exec("$options{cgi_bin}/$1") or
-                        die "Unable to execute $options{cgi_bin}/$1";
-              }
+                   #print "HTTP/1.1 200 OK\n";
+                   open(my $fh,'-|',"$options{cgi_bin}/$1") or
+                       die "Unable to execute $options{cgi_bin}/$1";
+                   my $status;
+                   my $cache = '';
+                   while (<$fh>) {
+                       if (/Status: (\d+\s+.+?)\n?$/) {
+                           $status = $1;
+                           print "HTTP/1.1 $status\n";
+                           print STDERR "'$status'\n";
+                           last;
+                       }
+                       $cache .= $_;
+                       if (/^$/) {
+                           print "HTTP/1.1 200 OK\n";
+                           last;
+                       }
+                   }
+                   print $cache;
+                   print <$fh>;
+                   close($fh) or die "Unable to close";
+               }
               elsif ($path =~ m{^/?css/bugs.css}) {
                    my $fh = IO::File->new($options{css},'r') or
                         die "Unable to open $options{css} for reading: $!";
@@ -511,7 +548,7 @@ sub select_bugs{
               elsif (/\s\w+\:/) {
                    push @bug_selections, $_;
               }
-         }
+          }
      }
      # Split archive:both into archive:1 and archive:0
      @bug_selections =
@@ -562,6 +599,10 @@ sub select_bugs{
             $bugs{$archived_bugs}{$_} = 1 for @{$bugs};
         }
      }
+     for my $bug (@bugs) {
+        $bugs{archived}{$bug} = 1;
+        $bugs{unarchived}{$bug} = 1;
+     }
      return \%bugs;
 }