use File::stat;
use File::Basename;
use File::Spec;
+use File::Find;
use IO::Dir;
use IO::File;
use IO::Uncompress::AnyUncompress;
use Encode qw(decode_utf8);
-use List::MoreUtils qw(natatime);
+use List::AllUtils qw(natatime);
my %options =
(debug => 0,
GetOptions(\%options,
'quick|q',
'service|s=s',
+ 'dsn=s',
'sysconfdir|c=s',
'progress!',
'spool_dir|spool-dir=s',
'versions' => {function => \&add_versions,
},
'debinfo' => {function => \&add_debinfo,
- arguments => {'0|null' => 0},
+ arguments => {'0|null' => 0,
+ 'debinfo_dir|debinfo-dir=s' => 0,
+ },
},
'maintainers' => {function => \&add_maintainers,
},
},
'logs' => {function => \&add_logs,
},
+ 'bugs_and_logs' => {function => \&add_bugs_and_logs,
+ },
'packages' => {function => \&add_packages,
arguments => {'ftpdists=s' => 1,
'suites=s@' => 0,
my $s = db_connect($options);
- my $time = 0;
- my $start_time = time;
my %tags;
my %severities;
my %queue;
my @bugs = @_;
my @bugs_to_update;
if ($options{quick}) {
- for my $bug (@bugs) {
- my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
- if (not defined $stat) {
- print STDERR "Unable to stat $bug $!\n";
- next;
- }
- my $rs = $s->resultset('Bug')->search({id=>$bug})->single();
- next if defined $rs and $stat->mtime <= $rs->last_modified()->epoch();
- push @bugs_to_update, $bug;
- }
+ @bugs_to_update =
+ bugs_to_update($s,$initialdir,@bugs);
} else {
- @bugs_to_update = @bugs;
+ @bugs_to_update = @bugs;
}
eval {
$s->txn_do(sub {
my ($options,$opts,$p,$config,$argv) = @_;
my @files = @{$argv};
+ if (exists $opts->{debinfo_dir} and not @files) {
+ find(sub {
+ if (-f $_ and /\.debinfo$/) {
+ push @files, $File::Find::name;
+ }
+ },
+ $opts->{debinfo_dir}
+ );
+ }
if (not @files) {
{
local $/ = "\n";
while (my @v = $it->()) {
my %cache;
my @debinfos;
- for my $file (@v) {
+FILE: for my $file (@v) {
my $fh = IO::File->new($file,'r') or
die "Unable to open $file for reading: $!";
my $f_stat = stat($file);
my $ct_date = DateTime->from_epoch(epoch => $f_stat->ctime);
+ my @file_debinfos;
while (<$fh>) {
chomp;
next unless length $_;
# the file, so we'll fudge it from the filename.
if (not defined $srcver) {
($srcname,$srcver) = ($binarch,$srcname);
- ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
+ ($binarch) = $file =~ /_([a-z0-9-]+)\.debinfo/;
}
- if (not defined $srcver) {
- print STDERR "malformed debinfo (no srcver): $file\n";
- next;
+ # It turns out that there are debinfo files which are horribly
+ # screwed up, and have junk in them. We need to discard them
+ # completely
+ if (not defined $srcname or
+ not defined $srcver or
+ not defined $binname or
+ not defined $binver or
+ $srcname !~ /^$config{package_name_re}$/o or
+ $binname !~ /^$config{package_name_re}$/o or
+ $srcver !~ /^$config{package_version_re}$/o or
+ $binver !~ /^$config{package_version_re}$/o
+ ) {
+ print STDERR "malformed debinfo: $file\n";
+ next FILE;
}
- push @debinfos,
+ push @file_debinfos,
[$binname,$binver,$binarch,$srcname,$srcver,$ct_date];
}
+ push @debinfos,
+ @file_debinfos;
}
$s->txn_do(
sub {
my ($options,$opts,$p,$config,$argv) = @_;
my $s = db_connect($options);
- my $maintainers = getsourcemaintainers();
+ my $maintainers = getsourcemaintainers() // {};
$p->target(2) if $p;
## get all of the maintainers, and add the missing ones
my $maints = $s->resultset('Maintainer')->
get_maintainers(values %{$maintainers});
- $p->update();
+ $p->update() if $p;
my @svs = $s->resultset('SrcVer')->
search({maintainer => undef
},
}
my $s = db_connect($options);
-
- my $time = 0;
- my $start_time = time;
-
walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
$p,
'log',
if ($options{quick}) {
my $rs = $s->resultset('Bug')->
search({id=>$bug})->single();
- next if defined $rs and
+ return if defined $rs and
$stat->mtime <= $rs->last_modified()->epoch();
}
eval {
});
}
+sub add_bugs_and_logs {
+ my ($options,$opts,$p,$config,$argv) = @_;
+
+ chdir($config->{spool_dir}) or
+ die "chdir $config->{spool_dir} failed: $!";
+
+ my $verbose = $options->{debug};
+
+ my $initialdir = "db-h";
+
+ if (defined $argv->[0] and $argv->[0] eq "archive") {
+ $initialdir = "archive";
+ }
+ my $s = db_connect($options);
+
+ my %tags;
+ my %severities;
+ my %queue;
+
+ walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+ $p,
+ 'summary',
+ $verbose,
+ sub {
+ my @bugs = @_;
+ my @bugs_to_update;
+ if ($options{quick}) {
+ @bugs_to_update =
+ bugs_to_update($s,$initialdir,@bugs);
+ } else {
+ @bugs_to_update = @bugs;
+ }
+ eval {
+ $s->txn_do(sub {
+ for my $bug (@bugs_to_update) {
+ load_bug(db => $s,
+ bug => $bug,
+ tags => \%tags,
+ severities => \%severities,
+ queue => \%queue);
+ }
+ });
+ };
+ if ($@) {
+ die "failure while trying to load bug: $@";
+ }
+ for my $bug (@bugs) {
+ my $stat = stat(getbugcomponent($bug,'log',$initialdir));
+ if (not defined $stat) {
+ print STDERR "Unable to stat $bug $!\n";
+ next;
+ }
+ if ($options{quick}) {
+ my $rs = $s->resultset('Bug')->
+ search({id=>$bug})->single();
+ return if defined $rs and
+ $stat->mtime <= $rs->last_modified()->epoch();
+ }
+ eval {
+ load_bug_log(db => $s,
+ bug => $bug);
+ };
+ if ($@) {
+ die "failure while trying to load bug log $bug\n$@";
+ }
+ }
+ },
+ 50
+ );
+ handle_load_bug_queue(db=>$s,
+ queue => \%queue,
+ );
+
+}
+
sub add_packages {
my ($options,$opts,$p,$config,$argv) = @_;
my ($options) = @_;
# connect to the database; figure out how to handle errors
# properly here.
- my $s = Debbugs::DB->connect($options->{service}) or
+ my $s = Debbugs::DB->connect($options->{dsn} //
+ $options->{service}) or
die "Unable to connect to database: ";
}
}
+sub bugs_to_update {
+ my ($s,$initialdir,@bugs) = @_;
+ my @bugs_to_update;
+ for my $bug (@bugs) {
+ my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
+ if (not defined $stat) {
+ print STDERR "Unable to stat $bug $!\n";
+ next;
+ }
+ my $rs = $s->resultset('Bug')->search({id=>$bug})->single();
+ next if defined $rs and $stat->mtime <= $rs->last_modified()->epoch();
+ push @bugs_to_update, $bug;
+ }
+ @bugs_to_update;
+}
+
__END__