]> git.donarmstrong.com Git - debbugs.git/blob - bin/debbugs-loadsql
document subcommands
[debbugs.git] / bin / debbugs-loadsql
1 #! /usr/bin/perl
2 # debbugs-loadsql is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2012 by Don Armstrong <don@donarmstrong.com>.
6
7
8 use warnings;
9 use strict;
10
11 use Getopt::Long qw(:config no_ignore_case);
12 use Pod::Usage;
13
14 =head1 NAME
15
16 debbugs-loadsql -- load debbugs sql database
17
18 =head1 SYNOPSIS
19
20 debbugs-loadsql [options] [subcommand]
21
22  Subcommands:
23   bugs help versions configuration
24   suites logs packages debinfo
25  Options:
26   --quick, -q only load changed things
27   --progress Show progress bar
28   --service, -s service name
29   --sysconfdir, -c postgresql service config dir
30   --spool-dir debbugs spool directory
31   --debug, -d debugging level (Default 0)
32   --help, -h display this help
33   --man, -m display manual
34
35 =head1 SUBCOMMANDS
36
37 =head2 help
38
39 Display this manual
40
41 =head2 bugs
42
43 Add bugs (subject, number, etc) to the database
44
45    --preload create all bugs first, then add information
46
47 =head2 versions
48
49 Add version descendant information (which version is based on which version) to
50 the database
51
52 =head2 maintainers
53
54 Add source maintainers to the BTS
55
56 =head2 configuration
57
58 Add debbugs configuration information (tags, severity, etc)
59
60 =head2 suites
61
62 Add suite information from ftp distribution
63
64   --ftpdists location of FTP mirror
65
66 =head2 logs
67
68 Add bug logs
69
70 =head2 packages
71
72 Add package information from the ftp archive
73
74   --ftpdists location of FTP mirror
75   --suites Suite to operate on
76
77 =head2 debinfo
78
79 Add package information from a debinfo file
80
81   --null -0 names of debinfo files are null separated
82
83 =head1 OPTIONS
84
85 =over
86
87 =item B<--quick, -q>
88
89 Only load changed bugs
90
91 =item B<--progress>
92
93 Show progress bar (requires Term::ProgressBar)
94
95 =item B<--service,-s>
96
97 Postgreql service to use; defaults to debbugs
98
99 =item B<--sysconfdir,-c>
100
101 System configuration directory to use; if not set, defaults to the
102 postgresql default. [Operates by setting PGSYSCONFDIR]
103
104 =item B<--spool-dir>
105
106 Debbugs spool directory; defaults to the value configured in the
107 debbugs configuration file.
108
109 =item B<--verbose>
110
111 Output more information about what is happening. Probably not useful
112 if you also set --progress.
113
114 =item B<--debug, -d>
115
116 Debug verbosity.
117
118 =item B<--help, -h>
119
120 Display brief useage information.
121
122 =item B<--man, -m>
123
124 Display this manual.
125
126 =back
127
128
129 =cut
130
131
132 use vars qw($DEBUG);
133
134 use Debbugs::Common (qw(checkpid lockpid get_hashname getparsedaddrs getbugcomponent make_list getsourcemaintainers),
135                      qw(hash_slice));
136 use Debbugs::Config qw(:config);
137 use Debbugs::Status qw(read_bug split_status_fields);
138 use Debbugs::Log;
139 use Debbugs::DB;
140 use Debbugs::DB::Load qw(:load_bug :load_package :load_suite);
141 use DateTime;
142 use File::stat;
143 use File::Basename;
144 use File::Spec;
145 use IO::Dir;
146 use IO::File;
147 use IO::Uncompress::AnyUncompress;
148 use Encode qw(decode_utf8);
149
150 my %options =
151     (debug           => 0,
152      help            => 0,
153      man             => 0,
154      verbose         => 0,
155      quiet           => 0,
156      quick           => 0,
157      service         => $config{debbugs_db},
158      progress        => 0,
159     );
160
161 Getopt::Long::Configure('pass_through');
162 GetOptions(\%options,
163            'quick|q',
164            'service|s=s',
165            'sysconfdir|c=s',
166            'progress!',
167            'spool_dir|spool-dir=s',
168            'verbose|v+',
169            'quiet+',
170            'debug|d+','help|h|?','man|m');
171 Getopt::Long::Configure('default');
172
173 pod2usage() if $options{help};
174 pod2usage({verbose=>2}) if $options{man};
175
176 $DEBUG = $options{debug};
177
178 my %subcommands =
179     ('bugs' => {function => \&add_bugs,
180                 arguments => {'preload' => 0},
181                },
182      'versions' => {function => \&add_versions,
183                    },
184      'debinfo' => {function => \&add_debinfo,
185                    arguments => {'0|null' => 0},
186                   },
187      'maintainers' => {function => \&add_maintainers,
188                       },
189      'configuration' => {function => \&add_configuration,
190                         },
191      'suites' => {function => \&add_suite,
192                   arguments => {'ftpdists=s' => 1,
193                                },
194                  },
195      'logs' => {function => \&add_logs,
196                },
197      'packages' => {function => \&add_packages,
198                     arguments => {'ftpdists=s' => 1,
199                                   'suites=s@' => 0,
200                                  },
201                    },
202      'help' => {function => sub {pod2usage({verbose => 2});}}
203     );
204
205 my @USAGE_ERRORS;
206 $options{verbose} = $options{verbose} - $options{quiet};
207
208 if ($options{progress}) {
209     eval "use Term::ProgressBar";
210     push @USAGE_ERRORS, "You asked for a progress bar, but Term::ProgressBar isn't installed" if $@;
211 }
212
213
214 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
215
216 if (exists $options{sysconfdir}) {
217     if (not defined $options{sysconfdir} or not length $options{sysconfdir}) {
218         delete $ENV{PGSYSCONFDIR};
219     } else {
220         $ENV{PGSYSCONFDIR} = $options{sysconfdir};
221     }
222 }
223
224 if (exists $options{spool_dir} and defined $options{spool_dir}) {
225     $config{spool_dir} = $options{spool_dir};
226 }
227
228 my $prog_bar;
229 if ($options{progress}) {
230     $prog_bar = eval "Term::ProgressBar->new({count => 1,ETA=>q(linear)})";
231     warn "Unable to initialize progress bar: $@" if not $prog_bar;
232 }
233
234
235 my ($subcommand) = shift @ARGV;
236 if (not defined $subcommand) {
237     $subcommand = 'help';
238     print STDERR "You must provide a subcommand; displaying usage.\n";
239     pod2usage();
240 } elsif (not exists $subcommands{$subcommand}) {
241     print STDERR "$subcommand is not a valid subcommand; displaying usage.\n";
242     pod2usage();
243 }
244
245 binmode(STDOUT,':encoding(UTF-8)');
246 binmode(STDERR,':encoding(UTF-8)');
247
248 my $opts =
249     handle_subcommand_arguments(\@ARGV,$subcommands{$subcommand}{arguments});
250 $subcommands{$subcommand}{function}->(\%options,$opts,$prog_bar,\%config,\@ARGV);
251
252 sub add_bugs {
253     my ($options,$opts,$p,$config,$argv) = @_;
254     chdir($config->{spool_dir}) or
255         die "chdir $config->{spool_dir} failed: $!";
256
257     my $verbose = $options->{debug};
258
259     my $initialdir = "db-h";
260
261     if (defined $argv->[0] and $argv->[0] eq "archive") {
262         $initialdir = "archive";
263     }
264     my $s = db_connect($options);
265
266
267     my $time = 0;
268     my $start_time = time;
269     my %tags;
270     my %severities;
271     my %queue;
272
273     if ($opts->{preload}) {
274         my @bugs;
275         walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
276                   undef,
277                   'summary',
278                   undef,
279                   sub {
280                       push @bugs,shift;
281                   });
282         $s->resultset('Bug')->quick_insert_bugs(@bugs);
283     }
284     walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
285               $p,
286               'summary',
287               $verbose,
288               sub {
289                   my $bug = shift;
290                   my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
291                   if (not defined $stat) {
292                       print STDERR "Unable to stat $bug $!\n";
293                       next;
294                   }
295                   if ($options{quick}) {
296                       my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
297                       next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
298                   }
299                   my $data = read_bug(bug => $bug,
300                                       location => $initialdir);
301                   eval {
302                       load_bug(db => $s,
303                                data => split_status_fields($data),
304                                tags => \%tags,
305                                severities => \%severities,
306                                queue => \%queue);
307                   };
308                   if ($@) {
309                       use Data::Dumper;
310                       print STDERR Dumper($data) if $DEBUG;
311                       die "failure while trying to load bug $bug\n$@";
312                   }
313               }
314              );
315     handle_load_bug_queue(db => $s,
316                           queue => \%queue);
317 }
318
319 sub add_versions {
320     my ($options,$opts,$p,$config,$argv) = @_;
321
322     my $s = db_connect($options);
323
324     my @files = @{$argv};
325     $p->target(scalar @files) if $p;
326     for my $file (@files) {
327         my $fh = IO::File->new($file,'r') or
328             die "Unable to open $file for reading: $!";
329         my @versions;
330         my %src_pkgs;
331         while (<$fh>) {
332             chomp;
333             next unless length $_;
334             if (/(\w[-+0-9a-z.]+) \(([^\(\) \t]+)\)/) {
335                 push @versions, [$1,$2];
336             }
337         }
338         close($fh);
339         my $ancestor_sv;
340         for my $i (reverse 0..($#versions)) {
341             my $sp;
342             if (not defined $src_pkgs{$versions[$i][0]}) {
343                 $src_pkgs{$versions[$i][0]} =
344                     $s->resultset('SrcPkg')->find_or_create({pkg => $versions[$i][0]});
345             }
346             $sp = $src_pkgs{$versions[$i][0]};
347             # There's probably something wrong if the source package
348             # doesn't exist, but we'll skip it for now
349             next unless defined $sp;
350             my $sv = $s->resultset('SrcVer')->find({src_pkg=>$sp->id(),
351                                                     ver => $versions[$i][1],
352                                                    });
353             if (defined $ancestor_sv and defined $sv and not defined $sv->based_on()) {
354                 $sv->update({based_on => $ancestor_sv->id()})
355             }
356             $ancestor_sv = $sv;
357         }
358         $p->update() if $p;
359     }
360     $p->remove() if $p;
361 }
362
363 sub add_debinfo {
364     my ($options,$opts,$p,$config,$argv) = @_;
365
366     my @files = @{$argv};
367     if (not @files) {
368        {
369            if ($opts->{0}) {
370                local $/ = "\0";
371            }
372            while (<STDIN>) {
373                push @files, $_;
374            }
375        }
376     }
377     return unless @files;
378     my $s = db_connect($options);
379     my %arch;
380     $p->target(scalar @files) if $p;
381     for my $file (@files) {
382         my $fh = IO::File->new($file,'r') or
383             die "Unable to open $file for reading: $!";
384         my $f_stat = stat($file);
385         while (<$fh>) {
386             chomp;
387             next unless length $_;
388             my ($binname, $binver, $binarch, $srcname, $srcver) = split;
389             # if $srcver is not defined, this is probably a broken
390             # .debinfo file [they were causing #686106, see commit
391             # 49c85ab8 in dak.] Basically, $binarch didn't get put into
392             # the file, so we'll fudge it from the filename.
393             if (not defined $srcver) {
394                 ($srcname,$srcver) = ($binarch,$srcname);
395                 ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
396             }
397             my $sp = $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
398             # update the creation date if the data we have is earlier
399             my $ct_date = DateTime->from_epoch(epoch => $f_stat->ctime);
400             if ($ct_date < $sp->creation) {
401                 $sp->creation($ct_date);
402                 $sp->last_modified(DateTime->now);
403                 $sp->update;
404             }
405             my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg =>$sp->id(),
406                                                               ver => $srcver});
407             if (not defined $sv->upload_date() or $ct_date < $sv->upload_date()) {
408                 $sv->upload_date($ct_date);
409                 $sv->update;
410             }
411             my $arch;
412             if (defined $arch{$binarch}) {
413                 $arch = $arch{$binarch};
414             } else {
415                 $arch = $s->resultset('Arch')->find_or_create({arch => $binarch});
416                 $arch{$binarch} = $arch;
417             }
418             my $bp = $s->resultset('BinPkg')->find_or_create({pkg => $binname});
419             $s->resultset('BinVer')->find_or_create({bin_pkg => $bp->id(),
420                                                      src_ver => $sv->id(),
421                                                      arch    => $arch->id(),
422                                                      ver        => $binver,
423                                                     });
424         }
425         $p->update() if $p;
426     }
427     $p->remove() if $p;
428 }
429
430 sub add_maintainers {
431     my ($options,$opts,$p,$config,$argv) = @_;
432
433     my $s = db_connect($options);
434     my $maintainers = getsourcemaintainers();
435     $p->target(2) if $p;
436     ## get all of the maintainers, and add the missing ones
437     my $maints = $s->resultset('Maintainer')->
438         get_maintainers(values %{$maintainers});
439     $p->update();
440     my @svs = $s->resultset('SrcVer')->
441         search({maintainer => undef
442                },
443               {join => 'src_pkg',
444                group_by => 'me.src_pkg, src_pkg.pkg',
445                result_class => 'DBIx::Class::ResultClass::HashRefInflator',
446                columns => [qw(me.src_pkg src_pkg.pkg)],
447               }
448               )->all();
449     $p->target(2+@svs) if $p;
450     $p->update() if $p;
451     for my $sv (@svs) {
452         if (exists $maintainers->{$sv->{src_pkg}{pkg}}) {
453             my $pkg = $sv->{src_pkg}{pkg};
454             my $maint = $maints->
455                {$maintainers->{$pkg}};
456             $s->txn_do(sub {$s->resultset('SrcVer')->
457                                 search({maintainer => undef,
458                                         'src_pkg.pkg' => $pkg
459                                        },
460                                       {join => 'src_pkg'}
461                                       )->update({maintainer => $maint})
462                                   });
463         }
464         $p->update() if $p;
465     }
466     $p->remove() if $p;
467 }
468
469 sub add_configuration {
470     my ($options,$opts,$p,$config,$argv) = @_;
471
472     my $s = db_connect($options);
473
474     # tags
475     # add all tags
476     my %tags;
477     for my $tag (@{$config{tags}}) {
478         $tags{$tag} = 1;
479         $s->resultset('Tag')->find_or_create({tag => $tag});
480     }
481     # mark obsolete tags
482     for my $tag ($s->resultset('Tag')->search_rs()->all()) {
483         next if exists $tags{$tag->tag};
484         $tag->obsolete(1);
485         $tag->update;
486     }
487
488     # severities
489     my %sev_names;
490     my $order = -1;
491     for my $sev_name (($config{default_severity},@{$config{severity_list}})) {
492         # add all severitites
493         my $sev = $s->resultset('Severity')->find_or_create({severity => $sev_name});
494         # mark strong severities
495         if (grep {$_ eq $sev_name} @{$config{strong_severities}}) {
496             $sev->strong(1);
497         }
498         $sev->ordering($order);
499         $sev->update();
500         $order++;
501         $sev_names{$sev_name} = 1;
502     }
503     # mark obsolete severities
504     for my $sev ($s->resultset('Severity')->search_rs()->all()) {
505         next if exists $sev_names{$sev->severity()};
506         $sev->obsolete(1);
507         $sev->update();
508     }
509 }
510
511 sub add_suite {
512     my ($options,$opts,$p,$config,$argv) = @_;
513     # suites
514
515     my $s = db_connect($options);
516     my $dist_dir = IO::Dir->new($opts->{ftpdists});
517     my @dist_names =
518         grep { $_ !~ /^\./ and
519                -d $opts->{ftpdists}.'/'.$_ and
520                not -l $opts->{ftpdists}.'/'.$_
521            } $dist_dir->read;
522     while (my $dist = shift @dist_names) {
523         my $dist_dir = $opts->{ftpdists}.'/'.$dist;
524         my ($dist_info,$package_files) =
525             read_release_file($dist_dir.'/Release');
526         load_suite($s,$dist_info);
527     }
528 }
529
530 sub add_logs {
531     my ($options,$opts,$p,$config,$argv) = @_;
532
533     chdir($config->{spool_dir}) or
534         die "chdir $config->{spool_dir} failed: $!";
535
536     my $verbose = $options->{debug};
537
538     my $initialdir = "db-h";
539
540     if (defined $argv->[0] and $argv->[0] eq "archive") {
541         $initialdir = "archive";
542     }
543     my $s = db_connect($options);
544
545
546     my $time = 0;
547     my $start_time = time;
548
549     walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
550               $p,
551               'log',
552               $verbose,
553               sub {
554                   my $bug = shift;
555                   my $stat = stat(getbugcomponent($bug,'log',$initialdir));
556                   if (not defined $stat) {
557                       print STDERR "Unable to stat $bug $!\n";
558                       next;
559                   }
560                   if ($options{quick}) {
561                       my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
562                       next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
563                   }
564                   eval {
565                       load_bug_log(db => $s,
566                                    bug => $bug);
567                   };
568                   if ($@) {
569                       die "failure while trying to load bug log $bug\n$@";
570                   }
571               });
572 }
573
574 sub add_packages {
575     my ($options,$opts,$p,$config,$argv) = @_;
576
577     my $dist_dir = IO::Dir->new($opts->{ftpdists});
578     my @dist_names =
579         grep { $_ !~ /^\./ and
580                -d $opts->{ftpdists}.'/'.$_ and
581                not -l $opts->{ftpdists}.'/'.$_
582            } $dist_dir->read;
583     my %s_p;
584     while (my $dist = shift @dist_names) {
585         my $dist_dir = $opts->{ftpdists}.'/'.$dist;
586         my ($dist_info,$package_files) =
587             read_release_file($dist_dir.'/Release');
588         $s_p{$dist_info->{Codename}} = $package_files;
589     }
590     my $tot = 0;
591     for my $suite (keys %s_p) {
592         for my $component (keys %{$s_p{$suite}}) {
593             $tot += scalar keys %{$s_p{$suite}{$component}};
594         }
595     }
596     $p->target($tot) if $p;
597     my $i = 0;
598     my $avg_pkgs = 0;
599     my $tot_suites = scalar keys %s_p;
600     my $done_suites=0;
601     my $completed_pkgs=0;
602     # parse packages files
603     for my $suite (keys %s_p) {
604         my @pkgs;
605         for my $component (keys %{$s_p{$suite}}) {
606             my @archs = keys %{$s_p{$suite}{$component}};
607             if (grep {$_ eq 'source'} @archs) {
608                 @archs = ('source',grep {$_ ne 'source'} @archs);
609             }
610             for my $arch (@archs) {
611                 my $pfh =  open_compressed_file($s_p{$suite}{$component}{$arch}) or
612                     die "Unable to open $s_p{$suite}{$component}{$arch} for reading: $!";
613                 local $_;
614                 local $/ = '';  # paragraph mode
615                 while (<$pfh>) {
616                     my %pkg;
617                     for my $field (qw(Package Maintainer Version Source)) {
618                         /^\Q$field\E: (.*)/m;
619                         $pkg{$field} = $1;
620                     }
621                     next unless defined $pkg{Package} and
622                         defined $pkg{Version};
623                     push @pkgs,[$arch,$component,\%pkg];
624                 }
625             }
626         }
627         my $s = db_connect($options);
628         if ($avg_pkgs==0) {
629             $avg_pkgs = @pkgs;
630         }
631         $p->target($avg_pkgs*($tot_suites-$done_suites-1)+
632                    $completed_pkgs+@pkgs) if $p;
633         load_packages($s,
634                       $suite,
635                       \@pkgs,
636                       $p);
637         $avg_pkgs=($avg_pkgs*$done_suites + @pkgs)/($done_suites+1);
638         $completed_pkgs += @pkgs;
639         $done_suites++;
640     }
641     $p->remove() if $p;
642 }
643
644 sub handle_subcommand_arguments {
645     my ($argv,$args) = @_;
646     my $subopt = {};
647     Getopt::Long::GetOptionsFromArray($argv,
648                               $subopt,
649                               keys %{$args},
650                              );
651     my @usage_errors;
652     for my $arg  (keys %{$args}) {
653         next unless $args->{$arg};
654         my $r_arg = $arg; # real argument name
655         $r_arg =~ s/[=\|].+//g;
656         if (not defined $subopt->{$r_arg}) {
657             push @usage_errors, "You must give a $r_arg option";
658         }
659     }
660     pod2usage(join("\n",@usage_errors)) if @usage_errors;
661     return $subopt;
662 }
663
664 sub get_lock{
665     my ($subcommand,$config,$options) = @_;
666     if (not lockpid($config->{spool_dir}.'/lock/debbugs-loadsql-$subcommand')) {
667         if ($options->{quick}) {
668             # If this is a quick run, just exit
669             print STDERR "Another debbugs-loadsql is running; stopping\n" if $options->{verbose};
670             exit 0;
671         }
672         print STDERR "Another debbugs-loadsql is running; stopping\n";
673         exit 1;
674     }
675 }
676
677 sub db_connect {
678     my ($options) = @_;
679     # connect to the database; figure out how to handle errors
680     # properly here.
681     my $s = Debbugs::DB->connect($options->{service}) or
682         die "Unable to connect to database: ";
683 }
684
685 sub open_compressed_file {
686     my ($file) = @_;
687     my $fh;
688     my $mode = '<:encoding(UTF-8)';
689     my @opts;
690     if ($file =~ /\.gz$/) {
691         $mode = '-|:encoding(UTF-8)';
692         push @opts,'gzip','-dc';
693     }
694     if ($file =~ /\.xz$/) {
695         $mode = '-|:encoding(UTF-8)';
696         push @opts,'xz','-dc';
697     }
698     if ($file =~ /\.bz2$/) {
699         $mode = '-|:encoding(UTF-8)';
700         push @opts,'bzip2','-dc';
701     }
702     open($fh,$mode,@opts,$file);
703     return $fh;
704 }
705
706 sub read_release_file {
707     my ($file) = @_;
708     # parse release
709     my $rfh =  open_compressed_file($file) or
710         die "Unable to open $file for reading: $!";
711     my %dist_info;
712     my $in_sha1;
713     my %p_f;
714     while (<$rfh>) {
715         chomp;
716         if (s/^(\S+):\s*//) {
717             if ($1 eq 'SHA1'or $1 eq 'SHA256') {
718                 $in_sha1 = 1;
719                 next;
720             }
721             $dist_info{$1} = $_;
722         } elsif ($in_sha1) {
723             s/^\s//;
724             my ($sha,$size,$f) = split /\s+/,$_;
725             next unless $f =~ /(?:Packages|Sources)(?:\.gz|\.xz)$/;
726             next unless $f =~ m{^([^/]+)/([^/]+)/([^/]+)$};
727             my ($component,$arch,$package_source) = ($1,$2,$3);
728             $arch =~ s/binary-//;
729             next if exists $p_f{$component}{$arch};
730             $p_f{$component}{$arch} = File::Spec->catfile(dirname($file),$f);
731         }
732     }
733     return (\%dist_info,\%p_f);
734 }
735
736 sub walk_bugs {
737     my ($dirs,$p,$what,$verbose,$sub) = @_;
738     my @dirs = @{$dirs};
739     my $tot_dirs = @dirs;
740     my $done_dirs = 0;
741     my $avg_subfiles = 0;
742     my $completed_files = 0;
743     while (my $dir = shift @dirs) {
744         printf "Doing dir %s ...\n", $dir if $verbose;
745
746         opendir(DIR, "$dir/.") or die "opendir $dir: $!";
747         my @subdirs = readdir(DIR);
748         closedir(DIR);
749
750         my @list = map { m/^(\d+)\.$what$/?($1):() } @subdirs;
751         $tot_dirs -= @dirs;
752         push @dirs, map { m/^(\d+)$/ && -d "$dir/$1"?("$dir/$1"):() } @subdirs;
753         $tot_dirs += @dirs;
754         if ($avg_subfiles == 0) {
755             $avg_subfiles = @list;
756         }
757
758         $p->target($avg_subfiles*($tot_dirs-$done_dirs)+$completed_files+@list) if $p;
759         $avg_subfiles = ($avg_subfiles * $done_dirs + @list) / ($done_dirs+1);
760         $done_dirs += 1;
761
762         for my $bug (@list) {
763             $completed_files++;
764             $p->update($completed_files) if $p;
765             print "Up to $completed_files bugs...\n" if ($completed_files % 100 == 0 && $verbose);
766             $sub->($bug);
767         }
768     }
769     $p->remove() if $p;
770 }
771
772
773
774 __END__