2 # $Id: errorlib.in,v 1.23 2003/05/24 22:43:55 cjwatson Exp $
4 sub F_SETLK { 6; } sub F_WRLCK{ 1; }
5 $flockstruct= 'sslll'; # And there ought to be something for this too.
8 return "" if ( $_[ 0 ] < 0 );
9 return sprintf "%02d", $_[ 0 ] % 100;
12 sub unlockreadbugmerge {
14 &unfilelock if $rv >= 2;
15 &unfilelock if $rv >= 1;
18 sub lockreadbugmerge {
19 local ($lref, $location) = @_;
21 if (!($data = &lockreadbug($lref, $location))) { return ( 0, undef ); }
22 if (!length($data{mergedwith})) { return ( 1, $data ); }
24 &filelock('lock/merge');
25 if (!&lockreadbug($lref, $location)) { &unfilelock; return ( 0, undef ); }
30 my ( $bugnum, $ext ) = @_;
31 my $archdir = sprintf "%02d", $bugnum % 100;
32 return 'archive' if ( -r "$gSpoolDir/archive/$archdir/$bugnum.$ext" );
33 return 'db' if ( -r "$gSpoolDir/db/$bugnum.$ext" );
34 return 'db-h' if ( -r "$gSpoolDir/db-h/$archdir/$bugnum.$ext" );
40 if ($location eq 'archive') {
41 return "$gSpoolDir/archive";
42 } elsif ($location eq 'db') {
43 return "$gSpoolDir/db";
45 return "$gSpoolDir/db-h";
50 local ($lref, $location) = @_;
51 my $hash = get_hashname($lref);
52 $path = getlocationpath($location);
53 if (!open(S,"$path/$hash/$lref.status")) { &unfilelock; return undef; }
55 chop($data{originator}= <S>);
56 chop($data{date}= <S>);
57 chop($data{subject}= <S>);
58 chop($data{msgid}= <S>);
59 chop($data{package}= <S>);
60 chop($data{keywords}= <S>);
61 chop($data{done}= <S>);
62 chop($data{forwarded}= <S>);
63 chop($data{mergedwith}= <S>);
64 chop($data{severity}= <S>);
65 chop($data{versions}= <S>);
66 chop($data{fixed_versions}= <S>);
68 $data{severity} = 'normal' if $data{severity} eq '';
73 local ($lref, $location) = @_;
74 &filelock("lock/$lref");
75 return readbug($lref, $location);
79 local ($ref, $data, $location) = @_;
80 my $hash = get_hashname($ref);
82 $path = getlocationpath($location);
83 open(S,">$path/$hash/$ref.status.new") || &quit("opening $path/$hash/$ref.status.new: $!");
85 "$data->{originator}\n".
90 "$data->{keywords}\n".
92 "$data->{forwarded}\n".
93 "$data->{mergedwith}\n".
94 "$data->{severity}\n".
95 "$data->{versions}\n".
96 "$data->{fixed_versions}\n") || &quit("writing $path/$hash/$ref.status.new: $!");
97 close(S) || &quit("closing $path/$hash/$ref.status.new: $!");
98 if (-e "$path/$hash/$ref.status") {
103 rename("$path/$hash/$ref.status.new","$path/$hash/$ref.status") ||
104 &quit("installing new $path/$hash/$ref.status: $!");
105 &bughook($change,$ref,
106 "$data->{originator}\n".
108 "$data->{subject}\n".
110 "$data->{package}\n".
111 "$data->{keywords}\n".
113 "$data->{forwarded}\n".
114 "$data->{mergedwith}\n".
115 "$data->{severity}\n".
116 "$data->{versions}\n".
117 "$data->{fixed_versions}\n");
122 # NB - NOT COMPATIBLE WITH `with-lock'
123 local ($lockfile,$flockpushno,$evalstring,$count,$errors,@s1,@s2) = @_;
124 $flockpushno= $#filelocks+1;
125 $count= 10; $errors= '';
128 open(FLOCK${flockpushno},\"> \$lockfile\") || die \"open: \$!\";
129 \$flockwant= pack(\$flockstruct,&F_WRLCK,0,0,1,0);".
131 fcntl(FLOCK$flockpushno,&F_SETLK,\$flockwant) || die \"setlk: \$!\";" : "
132 \$z= syscall(&SYS_fcntl,fileno(FLOCK$flockpushno),&F_SETLK,\$flockwant) < 0
133 && die \"syscall fcntl setlk: \$!\";") ."
134 (\@s1= lstat(\$lockfile)) || die \"lstat: \$!\";
135 (\@s2= stat(FLOCK$flockpushno)) || die \"fstat: \$!\";
136 join(',',\@s1) eq join(',',\@s2) || die \"file switched\";
139 last if eval $evalstring;
141 eval "close(FLOCK$flockpushno);";
144 &quit("failed to get lock on file $lockfile: $errors // $evalstring");
148 push(@cleanups,'unfilelock');
149 push(@filelocks,$lockfile);
153 local ($lockfile) = pop(@filelocks);
155 eval 'close(FLOCK'.($#filelocks+1).');' || warn "failed to close lock file: $!";
156 unlink($lockfile) || warn "failed to remove lock file: $!";
160 print DEBUG "quitting >$_[0]<\n";
162 while ($u= $cleanups[$#cleanups]) { &$u; }
166 %saniarray= ('<','lt', '>','gt', '&','amp', '"','quot');
171 while ($in =~ m/[<>&"]/) {
172 $out.= $`. '&'. $saniarray{$&}. ';';
179 sub update_realtime {
180 my ($file, $bug, $new) = @_;
182 # update realtime index.db
184 open(IDXDB, "<$file") or die "Couldn't open $file";
185 open(IDXNEW, ">$file.new");
188 while($line = <IDXDB>) {
189 my @line = split /\s/, $line;
190 last if ($line[1] == $bug);
194 if ($new eq "NOCHANGE") {
196 } elsif ($new eq "REMOVE") {
202 print IDXNEW while(<IDXDB>);
207 rename("$file.new", $file);
212 sub bughook_archive {
214 &filelock("debbugs.trace.lock");
215 &appendfile("debbugs.trace","archive $ref\n");
216 my $line = update_realtime(
217 "$gSpoolDir/index.db.realtime",
220 update_realtime("$gSpoolDir/index.archive.realtime",
226 my ( $type, $ref ) = ( shift, shift );
227 &filelock("debbugs.trace.lock");
229 &appendfile("debbugs.trace","$type $ref\n",@_);
231 my @stuff=split /\n/, "$_[0]\n\n\n\n\n\n\n";
234 my $whendone = "open";
235 my $severity = $gDefaultSeverity;
236 ($firstpkg = $stuff[4]) =~ s/[,\s].*$//;
237 $whendone = "forwarded" if length $stuff[7];
238 $whendone = "done" if length $stuff[6];
239 $severity = $stuff[9] if length $stuff[9];
241 my $k = sprintf "%s %d %d %s [%s] %s %s\n",
242 $firstpkg, $ref, $stuff[1], $whendone, $stuff[0],
243 $severity, $stuff[5];
245 update_realtime("$gSpoolDir/index.db.realtime", $ref, $k);
252 if (!open(AP,">>$file")) {
253 print DEBUG "failed open log<\n";
254 print DEBUG "failed open log err $!<\n";
255 &quit("opening $file (appendfile): $!");
257 print(AP @_) || &quit("writing $file (appendfile): $!");
258 close(AP) || &quit("closing $file (appendfile): $!");
263 my $type = $entity->effective_type;
264 if ($type eq 'text/plain' or
265 ($type =~ m#text/# and $type ne 'text/html') or
266 $type eq 'application/pgp') {
267 return $entity->bodyhandle;
268 } elsif ($type eq 'multipart/alternative') {
269 # RFC 2046 says we should use the last part we recognize.
270 for my $part (reverse $entity->parts) {
271 my $ret = getmailbody($part);
275 # For other multipart types, we just pretend they're
276 # multipart/mixed and run through in order.
277 for my $part ($entity->parts) {
278 my $ret = getmailbody($part);
287 map { s/^([\01-\07\030])/\030$1/gm } @log;
292 @severities= grep { not exists $gObsoleteSeverities{$_} } @gSeverityList;
293 @showseverities= @severities;
294 grep ($_= $_ eq '' ? $gDefaultSeverity : $_, @showseverities);
295 @strongseverities= @gStrongSeverities;
296 %displayshowseverities= %gSeverityDisplay;