chiark / gitweb /
Infra: dgit-repos-policy-debian: Fix db retry loop
[dgit.git] / infra / dgit-repos-policy-debian
index 30dbbbeca15cb71a9c0b7d47e460e76cfb5b17db..5d843a06b611423e805b734567bce3f875c4126d 100755 (executable)
@@ -206,8 +206,7 @@ sub add_taint_by_tag ($$) {
              " removed from NEW (ie, rejected) (or never arrived)");
 }
 
-sub action_check_package () {
-    getpackage();
+sub check_package () {
     return 0 unless $pkg_exists;
     return 0 unless $pkg_secret;
 
@@ -220,15 +219,16 @@ sub action_check_package () {
     my $age = time -  $mtime;
     printdebug "check_package age=$age\n";
 
-    return 0 if $age < $new_upload_propagation_slop;
-
-    return 0 if new_has_vsn_in_our_history();
-
     if (good_suite_has_vsn_in_our_history) {
        chmod $publicmode, "." or die $!;
+       $pkg_secret = 0;
        return 0;
     }
 
+    return 0 if $age < $new_upload_propagation_slop;
+
+    return 0 if new_has_vsn_in_our_history();
+
     printdebug "check_package secret, deleted, tainting\n";
 
     git_for_each_ref('refs/tags', sub {
@@ -239,6 +239,11 @@ sub action_check_package () {
     return FRESHREPO;
 }
 
+sub action_check_package () {
+    getpackage();
+    return check_package();
+}
+
 sub getpushinfo () {
     die unless @ARGV >= 4;
     $version = shift @ARGV;
@@ -256,6 +261,8 @@ sub action_push () {
     getpackage();
     getpushinfo();
 
+    check_package(); # might make package public, or might add taints
+
     return 0 unless $pkg_exists;
     return 0 unless $pkg_secret;
 
@@ -291,6 +298,7 @@ END
     $initq->execute($pkg);
 
     my @objscatcmd = qw(git);
+    push @objscatcmd, qw(--git-dir), $freshrepo if length $freshrepo;
     push @objscatcmd, qw(cat-file --batch);
     debugcmd '|',@objscatcmd if $debuglevel>=2;
 
@@ -444,21 +452,34 @@ 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 = '';
+
+       $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 $!;