X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Ferrorlib.in;h=a93c79bf3542e376203c79f1664de98dbe839130;hb=66af39a73332329a1227b6b9ea3489cd977f98e9;hp=d4256029a8af94d6b3ff5886f6a50d2956da33b4;hpb=1f49717b049fb6bcab868b75a866224a46db039f;p=debbugs.git diff --git a/scripts/errorlib.in b/scripts/errorlib.in index d425602..a93c79b 100755 --- a/scripts/errorlib.in +++ b/scripts/errorlib.in @@ -1,13 +1,11 @@ # -*- perl -*- -# $Id: errorlib.in,v 1.10 2002/10/27 13:40:17 ajt Exp $ -sub F_SETLK { 6; } sub F_WRLCK{ 1; } -$flockstruct= 'sslll'; # And there ought to be something for this too. - -sub get_hashname { - return "" if ( $_[ 0 ] < 0 ); - return sprintf "%02d", $_[ 0 ] % 100; -} +use Mail::Address; +use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522); +use Debbugs::Packages qw(:all); +use Debbugs::Common qw(:all); +use Debbugs::Status qw(:all); +use Carp; sub unlockreadbugmerge { local ($rv) = @_; @@ -16,147 +14,29 @@ sub unlockreadbugmerge { } sub lockreadbugmerge { - local ($lref) = @_; - if (!&lockreadbug($lref)) { return 0; } - if (!length($s_mergedwith)) { return 1; } + local ($lref, $location) = @_; + local $data; + if (!($data = &lockreadbug($lref, $location))) { return ( 0, undef ); } + if (!length($data->{mergedwith})) { return ( 1, $data ); } &unfilelock; &filelock('lock/merge'); - if (!&lockreadbug($lref)) { &unfilelock; return 0; } - return 2; -} - -sub lockreadbug { - local ($lref) = @_; - &filelock("lock/$lref"); - my $hash = get_hashname($lref); - if (!open(S,"db-h/$hash/$lref.status")) { &unfilelock; return 0; } - chop($s_originator= ); - chop($s_date= ); - chop($s_subject= ); - chop($s_msgid= ); - chop($s_package= ); - chop($s_keywords= ); - chop($s_done= ); - chop($s_forwarded= ); - chop($s_mergedwith= ); - chop($s_severity= ); - close(S); - $s_severity = 'normal' if $s_severity eq ''; - return 1; -} - -sub filelock { - # NB - NOT COMPATIBLE WITH `with-lock' - local ($lockfile,$flockpushno,$evalstring,$count,$errors,@s1,@s2) = @_; - $flockpushno= $#filelocks+1; - $count= 10; $errors= ''; - for (;;) { - $evalstring= " - open(FLOCK${flockpushno},\"> \$lockfile\") || die \"open: \$!\"; - \$flockwant= pack(\$flockstruct,&F_WRLCK,0,0,1,0);". - ($] >= 5.000 ? " - fcntl(FLOCK$flockpushno,&F_SETLK,\$flockwant) || die \"setlk: \$!\";" : " - \$z= syscall(&SYS_fcntl,fileno(FLOCK$flockpushno),&F_SETLK,\$flockwant) < 0 - && die \"syscall fcntl setlk: \$!\";") ." - (\@s1= lstat(\$lockfile)) || die \"lstat: \$!\"; - (\@s2= stat(FLOCK$flockpushno)) || die \"fstat: \$!\"; - join(',',\@s1) eq join(',',\@s2) || die \"file switched\"; - 1; - "; - last if eval $evalstring; - $errors .= $@; - eval "close(FLOCK$flockpushno);"; - if (--$count <=0) { - $errors =~ s/\n+$//; - &quit("failed to get lock on file $lockfile: $errors // $evalstring"); - } - sleep 10; - } - push(@cleanups,'unfilelock'); - push(@filelocks,$lockfile); -} - -sub unfilelock { - local ($lockfile) = pop(@filelocks); - pop(@cleanups); - eval 'close(FLOCK'.($#filelocks+1).');' || warn "failed to close lock file: $!"; - unlink($lockfile) || warn "failed to remove lock file: $!"; -} - -sub quit { - print DEBUG "quitting >$_[0]<\n"; - local ($u); - while ($u= $cleanups[$#cleanups]) { &$u; } - die "*** $_[0]\n"; + if (!&lockreadbug($lref, $location)) { &unfilelock; return ( 0, undef ); } + return ( 2, $data ); } %saniarray= ('<','lt', '>','gt', '&','amp', '"','quot'); sub sani { - local ($in) = @_; - local ($out); - while ($in =~ m/[<>&"]/) { - $out.= $`. '&'. $saniarray{$&}. ';'; - $in=$'; - } - $out.= $in; - $out; -} - -sub bughook { - my ( $type, $ref ) = ( shift, shift ); - &filelock("debbugs.trace.lock"); - &appendfile("debbugs.trace","$type $ref\n",@_); - my @stuff=split/\n/, "$_[0]\n\n\n\n\n\n\n"; - # XXX: bug: this'll only keep the most recent update until index.db - # starts getting overwritten by index.db.realtime after update - my $hash = get_hashname($ref); - unlink("$gSpoolDir/db/$ref.status.new"); - link("$gSpoolDir/db-h/$hash/$ref.status", "$gSpoolDir/db/$ref.status.new"); - rename("$gSpoolDir/db/$ref.status.new", "$gSpoolDir/db/$ref.status"); - open(IDXDB, "/org/bugs.debian.org/spool/index.db.realtime.new"); - while(my $line = ) { - @line = split /\s/, $line; - last if ($line[1] == $ref); - print IDXNEW $line; - } - my $firstpkg; - my $whendone = "open"; - my $severity = $gDefaultSeverity; - ($firstpkg = $stuff[4]) =~ s/[,\s].*$//; - $whendone = "forwarded" if length $stuff[7]; - $whendone = "done" if length $stuff[6]; - $severity = $stuff[9] if length $stuff[9]; - - printf IDXNEW "%s %d %d %s [%s] %s %s\n", - $firstpkg, $ref, $stuff[1], $whendone, $stuff[0], - $severity, $stuff[5]; - print IDXNEW while(); - close(IDXNEW); - close(IDXDB); - rename("/org/bugs.debian.org/spool/index.db.realtime.new", - "/org/bugs.debian.org/spool/index.db.realtime"); - &unfilelock; -} - -sub appendfile { - my $file = shift; - if (!open(AP,">>$file")) { - print DEBUG "failed open log<\n"; - print DEBUG "failed open log err $!<\n"; - &quit("opening $file (appendfile): $!"); - } - print(AP @_) || &quit("writing $file (appendfile): $!"); - close(AP) || &quit("closing $file (appendfile): $!"); + my ($in) = @_; + carp "You should be using HTML::Entities instead."; + $in =~ s/([<>&"])/$saniarray{$1}/g; + return $in; } sub getmailbody { my $entity = shift; my $type = $entity->effective_type; - if ($type eq 'text/plain' or - ($type =~ m#text/# and $type ne 'text/html') or + if ($type =~ m#text/(?!html|enriched)# or $type eq 'application/pgp') { return $entity->bodyhandle; } elsif ($type eq 'multipart/alternative') { @@ -176,17 +56,26 @@ sub getmailbody { return undef; } +sub get_addresses { + return + map { $_->address() } + map { Mail::Address->parse($_) } @_; +} + sub escapelog { my @log = @_; map { s/^([\01-\07\030])/\030$1/gm } @log; return \@log; } - -@severities= @gSeverityList; +@severities= grep { not exists $gObsoleteSeverities{$_} } @gSeverityList; @showseverities= @severities; grep ($_= $_ eq '' ? $gDefaultSeverity : $_, @showseverities); -@strongseverities= @gStrongSeverities; %displayshowseverities= %gSeverityDisplay; +# compatibility +if (defined $gFowardList and not defined $gForwardList) { + $gForwardList = $gFowardList; +} + 1;