]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/gen-indices.in
merge changes from dla source
[debbugs.git] / scripts / gen-indices.in
index 730880a067d8d25f9fe318cd30eee4ca1d2248eb..11775e479edc1f87feb73839a73d7f07b06f628d 100755 (executable)
@@ -76,7 +76,7 @@ pod2usage(1) if $options{help};
 pod2usage(-verbose=>2) if $options{man};
 
 use Debbugs::Config qw(:config);
-use Debbugs::Common qw(getparsedaddrs getbugcomponent);
+use Debbugs::Common qw(getparsedaddrs getbugcomponent lockpid);
 use Debbugs::Status qw(readbug);
 
 chdir($config{spool_dir}) or die "chdir $config{spool_dir} failed: $!";
@@ -92,8 +92,18 @@ if (defined $ARGV[0] and $ARGV[0] eq "archive") {
     $suffix = "-arc";
 }
 
+if (not lockpid($config{spool_dir}.'/lock/gen-indices')) {
+     if ($options{quick}) {
+         # If this is a quick run, just exit
+         print STDERR "Another gen-indices is running; stopping\n" if $verbose;
+         exit 0;
+     }
+     print STDERR "Another gen-indices is running; stopping\n";
+     exit 1;
+}
+
 # NB: The reverse index is special; it's used to clean up during updates to bugs
-my @indexes = ('package', 'tag', 'severity','owner','submitter-email','reverse');
+my @indexes = ('package', 'tag', 'severity','owner','submitter-email','status','reverse');
 my $indexes;
 my %slow_index = ();
 my %fast_index = ();
@@ -167,7 +177,7 @@ my @dirs = ($initialdir);
 while (my $dir = shift @dirs) {
        printf "Doing dir %s ...\n", $dir if $verbose;
 
-       opendir(DIR, "$dir/.") or die "opendir $dir: $!\n";
+       opendir(DIR, "$dir/.") or die "opendir $dir: $!";
        my @subdirs = readdir(DIR);
        closedir(DIR);
 
@@ -176,7 +186,11 @@ while (my $dir = shift @dirs) {
 
        for my $bug (@list) {
                print "Up to $cnt bugs...\n" if (++$cnt % 100 == 0 && $verbose);
-               my $stat = stat(getbugcomponent($bug,'summary'));
+               my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
+               if (not defined $stat) {
+                    print STDERR "Unable to stat $bug $!\n";
+                    next;
+               }
                next if $stat->mtime < $time;
                my $fdata = readbug($bug, $initialdir);
                addbugtoindex("package", $bug, split /[\s,]+/, $fdata->{"package"});
@@ -207,3 +221,4 @@ for my $i (@indexes) {
        system('touch','-d',"1/1/1970 UTC + ${start_time}secs","$indexdest/by-$i$suffix.idx");
 }
 
+unlink($config{spool_dir}.'/lock/gen-indices')