]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/debbugs-loadsql
skip bad .debinfo files when loading them
[debbugs.git] / bin / debbugs-loadsql
index 17edf44fa727d67e09afd3b520e4165aa71f1cd8..e639e0ee27793438f82ffaab54d9671fc847be2d 100755 (executable)
@@ -142,6 +142,7 @@ use DateTime;
 use File::stat;
 use File::Basename;
 use File::Spec;
+use File::Find;
 use IO::Dir;
 use IO::File;
 use IO::Uncompress::AnyUncompress;
@@ -184,7 +185,9 @@ my %subcommands =
      '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,
                       },
@@ -369,6 +372,15 @@ sub add_debinfo {
     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";
@@ -387,11 +399,12 @@ sub add_debinfo {
     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 $_;
@@ -402,15 +415,28 @@ sub add_debinfo {
                # 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 {
@@ -427,12 +453,12 @@ sub add_maintainers {
     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
               },