X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fgen-indices;h=7a8670d96ffb8c69fe90e73185e78a156792183b;hb=ebc68050faa07f08c26110d0f8de15c79fa522b8;hp=11775e479edc1f87feb73839a73d7f07b06f628d;hpb=90b39e8c4b91cb1e21df851d136085a1237243b8;p=debbugs.git diff --git a/scripts/gen-indices b/scripts/gen-indices index 11775e4..7a8670d 100755 --- a/scripts/gen-indices +++ b/scripts/gen-indices @@ -1,8 +1,13 @@ #!/usr/bin/perl +# gen-indices generates bug index files, and is released +# under the terms of the GPL version 2, or any later version, at your +# option. See the file README and COPYING for more information. -# Generates by-*.idx files for the CGI scripts # Copyright (c) 2005/08/03 Anthony Towns -# GPL v2 +# Copyright 2007, 2008 by Don Armstrong . + +use warnings; +use strict; use DB_File; use MLDBM qw(DB_FILE Storable); @@ -12,12 +17,11 @@ use File::Copy; use Getopt::Long; use Pod::Usage; -use warnings; -use strict; - use File::stat; use List::Util qw(min); +use Debbugs::Common qw(make_list); + =head1 NAME gen-indices - Generates index files for the cgi scripts @@ -37,7 +41,7 @@ gen-indices - Generates index files for the cgi scripts =over -=itme B<--quick> +=item B<--quick> Only update changed bugs @@ -77,7 +81,9 @@ pod2usage(-verbose=>2) if $options{man}; use Debbugs::Config qw(:config); use Debbugs::Common qw(getparsedaddrs getbugcomponent lockpid); -use Debbugs::Status qw(readbug); +use Debbugs::Status qw(readbug split_status_fields); +use Debbugs::Log; +use Debbugs::UTF8 qw(encode_utf8_structure); chdir($config{spool_dir}) or die "chdir $config{spool_dir} failed: $!"; @@ -103,7 +109,7 @@ if (not lockpid($config{spool_dir}.'/lock/gen-indices')) { } # NB: The reverse index is special; it's used to clean up during updates to bugs -my @indexes = ('package', 'tag', 'severity','owner','submitter-email','status','reverse'); +my @indexes = ('package', 'tag', 'severity','owner','submitter-email','status','correspondent','affects','reverse'); my $indexes; my %slow_index = (); my %fast_index = (); @@ -171,6 +177,7 @@ sub emailfromrfc822 { return $email; } +my $modification_made = 0; my $cnt = 0; my @dirs = ($initialdir); @@ -192,15 +199,33 @@ while (my $dir = shift @dirs) { next; } next if $stat->mtime < $time; - my $fdata = readbug($bug, $initialdir); - addbugtoindex("package", $bug, split /[\s,]+/, $fdata->{"package"}); - addbugtoindex("tag", $bug, split /[\s,]+/, $fdata->{"keywords"}); + my ($fdata) = encode_utf8_structure(split_status_fields(readbug($bug, $initialdir))); + $modification_made = 1; + addbugtoindex("package", $bug, make_list($fdata->{package})); + addbugtoindex("tag", $bug, make_list($fdata->{keywords})); + addbugtoindex("affects", $bug, make_list($fdata->{"affects"})); addbugtoindex('submitter-email', $bug, map {lc($_->address)} getparsedaddrs($fdata->{originator})); addbugtoindex("severity", $bug, $fdata->{"severity"}); addbugtoindex("owner", $bug, map {lc($_->address)} getparsedaddrs($fdata->{"owner"})); - } + # handle log entries + # do this in eval to avoid exploding on jacked logs + eval { + my $log = Debbugs::Log->new(bug_num => $bug); + my @correspondents; + while (my $record = $log->read_record()) { + next unless $record->{type} eq 'incoming-recv'; + # we use a regex here, because a full mime parse will be slow. + my ($from) = $record->{text} =~ /^From:\s+(.+?)^\S/ism; + push @correspondents, map {lc($_->address)} getparsedaddrs($from); + } + addbugtoindex('correspondent',$bug,@correspondents) if @correspondents; + }; + if ($@) { + print STDERR "Problem dealing with log of $bug: $@"; + } + } } if (not $options{quick}) { @@ -213,12 +238,17 @@ if (not $options{quick}) { } } - for my $i (@indexes) { - untie %{$slow_index{$i}}; + untie %{$slow_index{$i}}; + # Only move if we've made changes, otherwise unlink + if ($modification_made) { move("$indexdest/by-$i$suffix.idx.new", "$indexdest/by-$i$suffix.idx"); # We do this, because old versions of touch don't support -d '@epoch' system('touch','-d',"1/1/1970 UTC + ${start_time}secs","$indexdest/by-$i$suffix.idx"); + } + else { + unlink("$indexdest/by-$i$suffix.idx.new"); + } } unlink($config{spool_dir}.'/lock/gen-indices')