chiark / gitweb /
Avoid use of "my $_", which is not portable
[dgit.git] / infra / dgit-repos-policy-debian
index e665a636566242c95b844c518a3eebaad93870ce..339081e93987c569783665c10aef56c80dbcb663 100755 (executable)
@@ -86,7 +86,9 @@ our %deliberately;
 sub apiquery ($) {
     my ($subpath) = @_;
     local $/=undef;
-    my $cmd = "$dgitlive/dgit -d$distro \$DGIT_TEST_OPTS";
+    my $dgit = "$dgitlive/dgit";
+    $dgit = "dgit" if !stat_exists $dgit;
+    my $cmd = "$dgit -d$distro \$DGIT_TEST_OPTS";
     $cmd .= " -".("D" x $debuglevel) if $debuglevel;
     $cmd .= " archive-api-query $subpath";
     printdebug "apiquery $cmd\n";
@@ -452,21 +454,38 @@ if (!$fn) {
 my $sleepy=0;
 my $rcode;
 
+my $db_busy_exception= 'Debian::Dgit::Policy::Debian::DB_BUSY';
+
+my @orgargv = @ARGV;
+
 for (;;) {
-    poldb_setup(poldb_path($repos));
-    $stderr = '';
+    @ARGV = @orgargv;
+    eval {
+       poldb_setup(poldb_path($repos));
+       $stderr = '';
+
+       eval ($ENV{'DGIT_DRS_RPD_TEST_DBLOOP_HOOK'}//'');
+       die $@ if length $@;
+       # used by tests/tests/debpolicy-dbretry
+
+       $poldbh->{HandleError} = sub {
+           return 0 unless $poldbh->err == 5; # SQLITE_BUSY, not in .pm :-(
+           die bless { }, $db_busy_exception;
+       };
 
-    $rcode = $fn->();
-    die unless defined $rcode;
+       $rcode = $fn->();
+       die unless defined $rcode;
 
-    eval { $poldbh->commit; };
+       $poldbh->commit;
+    };
     last unless length $@;
+    die $@ unless ref $@ eq $db_busy_exception;
 
     die if $sleepy >= 20;
-    print STDERR "[policy database busy, retrying]\n";
-    sleep ++$sleepy;
+    $sleepy++;
+    print STDERR "[policy database busy, retrying (${sleepy}s)]\n";
 
-    $poldbh->rollback;
+    eval { $poldbh->rollback; };
 }
 
 print STDERR $stderr or die $!;