]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/gen-indices.in
close race condition when updating bts indices
[debbugs.git] / scripts / gen-indices.in
index 84af448ebe1092aecb89d4d92eed2cbbf2c8aa2a..05136f663385549d0d15475230151edb7841ecee 100755 (executable)
@@ -14,6 +14,7 @@ use Getopt::Long;
 use Pod::Usage;
 
 use File::stat;
+use List::Util qw(min);
 
 =head1 NAME
 
@@ -85,13 +86,14 @@ if ($ARGV[0] eq "archive") {
 my @indexes = ('package', 'tag', 'severity', 'submitter-email');
 my %index = ();
 my $time = undef;
+my $start_time = time;
 for my $i (@indexes) {
        %{$index{$i}} = {};
        if ($options{quick}) {
             if (-e "$indexdest/by-$i${suffix}.idx") {
                  system('cp','-a',"$indexdest/by-$i${suffix}.idx","$indexdest/by-$i${suffix}.idx.new") == 0
                       or die "Error creating the new index";
-                 my $stat = stat("$indexdest/by-$i${suffix}.idx");
+                 my $stat = stat("$indexdest/by-$i${suffix}.idx") or die "Unable to stat $indexdest/by-$i${suffix}.idx";
                  $time = defined $time ? min($time,$stat->mtime) : $stat->mtime;
             }
             tie %{$index{$i}}, DB_File => "$indexdest/by-$i$suffix.idx.new",
@@ -137,12 +139,12 @@ while (my $dir = shift @dirs) {
        my @subdirs = readdir(DIR);
        closedir(DIR);
 
-       my @list = map { s/\.summary$//; $_ } grep { m/^\d+\.summary$/ } @subdirs;
-       push @dirs, map { "$dir/$_" } grep { m/^\d+$/ } @subdirs;
+       my @list = map { m/^(\d+)\.summary$/?($1):() } @subdirs;
+       push @dirs, map { m/^(\d+)$/ && -d "$dir/$1"?("$dir/$1"):() } @subdirs;
 
        for my $f (@list) {
                print "Up to $cnt bugs...\n" if (++$cnt % 100 == 0 && $verbose);
-               my $stat = stat($f);
+               my $stat = stat(getbugcomponent($f,'summary'));
                next if $stat->mtime < $time;
                my $fdata = readbug($f, $initialdir);
                for my $p (split /[\s,]+/, $fdata->{"package"}) {
@@ -160,4 +162,5 @@ while (my $dir = shift @dirs) {
 for my $i (@indexes) {
        untie %{$indexes{$i}};
        move("$indexdest/by-$i$suffix.idx.new", "$indexdest/by-$i$suffix.idx");
+       system('touch','-d',"1/1/1970 + ${start_time}secs","$indexdest/by-$i$suffix.idx");
 }