X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=infra%2Fdgit-repos-policy-debian;h=41a5551faa005c591dfb0fed62467b9387e88dff;hp=7e459cc7304f27b71b4e0fe8d21b53bfd80ab164;hb=2d2bbb5a3356b960f18683773c6b370bcce9660f;hpb=38ce8a2a9efada278c498b0fb1ddce63560de04a diff --git a/infra/dgit-repos-policy-debian b/infra/dgit-repos-policy-debian index 7e459cc7..41a5551f 100755 --- a/infra/dgit-repos-policy-debian +++ b/infra/dgit-repos-policy-debian @@ -2,18 +2,23 @@ # dgit repos policy hook script for Debian use strict; +$SIG{__WARN__} = sub { die $_[0]; }; + use POSIX; use JSON; -use File::Temp; +use File::Temp qw(tempfile); +use DBI; +use IPC::Open2; use Debian::Dgit qw(:DEFAULT :policyflags); +use Debian::Dgit::Policy::Debian; our $distro = shift @ARGV // die "need DISTRO"; our $repos = shift @ARGV // die "need DGIT-REPOS-DIR"; +our $dgitlive = shift @ARGV // die "need DGIT-LIVE-DIR"; our $action = shift @ARGV // die "need ACTION"; our $publicmode = 02775; -our $policydb = "dbi:SQLite:$repos/policy.sqlite3"; our $new_upload_propagation_slop = 3600*4 + 100; our $poldbh; @@ -71,45 +76,12 @@ our %deliberately; # - .dsc of NEW dgit package has corresponding dgit-repo but not # publicly readable -sub poldb_setup () { - $poldbh ||= DBI->connect($policydb,'','', { - RaiseError=>1, PrintError=>1, AutoCommit=>0 - }); - $poldbh->do("PRAGMA foreign_keys = ON"); - - $poldbh->do(<do(<do(< 1; + die unless @ARGV >= 1; $pkg = shift @ARGV; - die if $pkg =~ m#[^-+.0-9a-z]#; - die unless $pkg =~ m#^[^-]#; + die unless $pkg =~ m/^$package_re$/; - $pkgdir = "$repos/$pkg"; - if (!stat $pkgdir) { - die "$pkgdir $!" unless $!==ENOENT; - $pkg_exists = 0; - } - $pkg_exists = 1; - $pkg_secret = !!(~(stat _)[2] & 05); + statpackage(); } sub add_taint ($$) { @@ -179,7 +154,7 @@ sub add_taint ($$) { close $tf or die $!; $_ = ; - m/^(\w+) (\w+) (\d+)\n/ or die "$objline ?"; + m/^(\w+) (\w+) (\d+)\n/ or die "$_ ?"; my $gitobjid = $1; my $gitobjtype = $2; my $bytes = $3; @@ -228,9 +203,8 @@ sub action__check_package () { git_for_each_ref('refs/tags', sub { my ($objid,$objtype,$fullrefname,$tagname) = @_; - add_taint_by_tag($tagname,$refobjid); + add_taint_by_tag($tagname,$objid); }); - $?=0; $!=0; close TAGL or die "git for-each-ref $? $!"; return FRESHREPO; } @@ -273,7 +247,11 @@ sub action_push () { } sub action_push_confirm () { - my $initq = $dbh->prepare(<prepare(<fetchrow_hashref()) { push @taintids, $taint->{taint_id}; - print $chkinput, $taint->{gitobjid}, "\n" or die $!; + print $chkinput $taint->{gitobjid}, "\n" or die $!; } flush $chkinput or die $!; seek $chkinput,0,0 or die $!; - my $checkpid = open2("<&$chkinput", \*CHKOUT, qw(git cat-file --batch)); - $checkpid or die $!; + my $checkpid = open CHKOUT, "-|" // die $!; + if (!$checkpid) { + open STDIN, "<&", $chkinput or die $!; + exec qw(git cat-file --batch) or die $!; + } my ($taintinfoq,$overridesanyq,$untaintq,$overridesq); my $overridesstmt = <) { - my $taintid = shift @taintids; - die unless defined $taintid; + while (my $taintid = shift @taintids) { + # git cat-file prints a spurious newline after it gets EOF + # This is not documented. I guess it might go away. So we + # just read what we expect and then let it get SIGPIPE. + $!=0; $_ = ; + die "$? $!" unless defined $_; next if m/^\w+ missing$/; - die unless m/^(\w+) (\s+) (\d+)\s/; - my ($objid,$objtype,$nbytes) = @_; + die unless m/^(\w+) (\w+) (\d+)\s/; + my ($objid,$objtype,$nbytes) = ($1,$2,$3); - read CHKOUT, $_, $nbytes == $bytes or last; + my $drop; + (read CHKOUT, $drop, $nbytes) == $nbytes or die; - $taintinfoq ||= $dbh->prepare(<prepare(<execute($taintid); @@ -328,7 +311,7 @@ END die unless $ti; my $timeshow = defined $ti->{time} - ? " at time ".strftime("%Y-%m-%d %H:%M:%S Z", gmtime $ti->time) + ? " at time ".strftime("%Y-%m-%d %H:%M:%S Z", gmtime $ti->{time}) : ""; my $pkgshow = length $ti->{package} ? "package $ti->{package}" @@ -337,15 +320,15 @@ END $stderr .= <{comment} END - $overridesq ||= $dbh->prepare($overridesstmt); + $overridesq ||= $poldbh->prepare($overridesstmt); $overridesq->execute(@overridesv, $taintid); my ($ovwhy) = $overridesq->fetchrow_array(); if (!defined $ovwhy) { - $overridesanyq ||= $dbh->prepare(<prepare(<execute($taintid); @@ -360,16 +343,13 @@ END $stderr .= <prepare(<prepare(<execute($taint_id); + $untaintq->execute($taintid); } } - if (@taintids) { - $?=0; my $gotpid = waitpid $checkpid, WNOHANG; - die "@taintids $gotpid $? $!"; - } + close CHKOUT; if ($mustreject) { $stderr .= < 1); + chmod $newmode, $freshrepo or die $!; + } + } + return 0; } -$cmd =~ y/-/_/; -my $fn = ${*::}{"action__$cmd"}; +$action =~ y/-/_/; +my $fn = ${*::}{"action_$action"}; if (!$fn) { exit 0; } my $sleepy=0; +our $rcode = 127; for (;;) { - poldb_setup(); + poldb_setup(poldb_path($repos)); $stderr = ''; - my $rcode = $fn->(); + $rcode = $fn->(); die unless defined $rcode; eval { $poldbh->commit; };