2 # $Id: errorlib.in,v 1.29 2003/06/06 17:56:05 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-h' if ( -r "$gSpoolDir/db-h/$archdir/$bugnum.$ext" );
34 return 'db' if ( -r "$gSpoolDir/db/$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 my ($bugnum, $ext, $location) = @_;
52 $location = getbuglocation($bugnum, $ext) unless defined $location;
53 my $dir = getlocationpath($location);
54 return undef unless $dir;
55 if ($location eq 'db') {
56 return "$dir/$bugnum.$ext";
58 my $hash = get_hashname($bugnum);
59 return "$dir/$hash/$bugnum.$ext";
64 local ($lref, $location) = @_;
65 my $status = getbugcomponent($lref, 'status', $location);
66 return undef unless defined $status;
67 if (!open(S,$status)) { return undef; }
69 chop($data{originator}= <S>);
70 chop($data{date}= <S>);
71 chop($data{subject}= <S>);
72 chop($data{msgid}= <S>);
73 chop($data{package}= <S>);
74 chop($data{keywords}= <S>);
75 chop($data{done}= <S>);
76 chop($data{forwarded}= <S>);
77 chop($data{mergedwith}= <S>);
78 chop($data{severity}= <S>);
79 chop($data{versions}= <S>);
80 chop($data{fixed_versions}= <S>);
82 $data{severity} = 'normal' if $data{severity} eq '';
87 local ($lref, $location) = @_;
88 &filelock("lock/$lref");
89 my $data = readbug($lref, $location);
90 &unfilelock unless defined $data;
95 local ($ref, $data, $location) = @_;
97 my $status = getbugcomponent($ref, 'status', $location);
98 &quit("can't find location for $ref") unless defined $status;
99 open(S,"> $status.new") || &quit("opening $status.new: $!");
101 "$data->{originator}\n".
103 "$data->{subject}\n".
105 "$data->{package}\n".
106 "$data->{keywords}\n".
108 "$data->{forwarded}\n".
109 "$data->{mergedwith}\n".
110 "$data->{severity}\n".
111 "$data->{versions}\n".
112 "$data->{fixed_versions}\n") || &quit("writing $status.new: $!");
113 close(S) || &quit("closing $status.new: $!");
119 rename("$status.new",$status) ||
120 &quit("installing new $status: $!");
121 &bughook($change,$ref,
122 "$data->{originator}\n".
124 "$data->{subject}\n".
126 "$data->{package}\n".
127 "$data->{keywords}\n".
129 "$data->{forwarded}\n".
130 "$data->{mergedwith}\n".
131 "$data->{severity}\n".
132 "$data->{versions}\n".
133 "$data->{fixed_versions}\n");
142 # NB - NOT COMPATIBLE WITH `with-lock'
143 local ($lockfile,$flockpushno,$evalstring,$count,$errors,@s1,@s2) = @_;
144 $flockpushno= $#filelocks+1;
145 $count= 10; $errors= '';
148 open(FLOCK${flockpushno},\"> \$lockfile\") || die \"open: \$!\";
149 \$flockwant= pack(\$flockstruct,&F_WRLCK,0,0,1,0);".
151 fcntl(FLOCK$flockpushno,&F_SETLK,\$flockwant) || die \"setlk: \$!\";" : "
152 \$z= syscall(&SYS_fcntl,fileno(FLOCK$flockpushno),&F_SETLK,\$flockwant) < 0
153 && die \"syscall fcntl setlk: \$!\";") ."
154 (\@s1= lstat(\$lockfile)) || die \"lstat: \$!\";
155 (\@s2= stat(FLOCK$flockpushno)) || die \"fstat: \$!\";
156 join(',',\@s1) eq join(',',\@s2) || die \"file switched\";
159 last if eval $evalstring;
161 eval "close(FLOCK$flockpushno);";
164 &quit("failed to get lock on file $lockfile: $errors // $evalstring");
168 push(@cleanups,'unfilelock');
169 push(@filelocks,$lockfile);
173 if (@filelocks == 0) {
174 warn "unfilelock called with no active filelocks!\n";
177 local ($lockfile) = pop(@filelocks);
179 eval 'close(FLOCK'.($#filelocks+1).');' || warn "failed to close lock file $lockfile: $!";
180 unlink($lockfile) || warn "failed to remove lock file $lockfile: $!";
184 print DEBUG "quitting >$_[0]<\n";
186 while ($u= $cleanups[$#cleanups]) { &$u; }
190 %saniarray= ('<','lt', '>','gt', '&','amp', '"','quot');
195 while ($in =~ m/[<>&"]/) {
196 $out.= $`. '&'. $saniarray{$&}. ';';
203 sub update_realtime {
204 my ($file, $bug, $new) = @_;
206 # update realtime index.db
208 open(IDXDB, "<$file") or die "Couldn't open $file";
209 open(IDXNEW, ">$file.new");
213 while($line = <IDXDB>) {
214 @line = split /\s/, $line;
215 last if ($line[1] >= $bug);
220 if ($new eq "NOCHANGE") {
221 print IDXNEW $line if ($line ne "" && $line[1] == $ref);
222 } elsif ($new eq "REMOVE") {
227 if ($line ne "" && $line[1] > $bug) {
232 print IDXNEW while(<IDXDB>);
237 rename("$file.new", $file);
242 sub bughook_archive {
244 &filelock("debbugs.trace.lock");
245 &appendfile("debbugs.trace","archive $ref\n");
246 my $line = update_realtime(
247 "$gSpoolDir/index.db.realtime",
250 update_realtime("$gSpoolDir/index.archive.realtime",
256 my ( $type, $ref ) = ( shift, shift );
257 &filelock("debbugs.trace.lock");
259 &appendfile("debbugs.trace","$type $ref\n",@_);
261 my @stuff=split /\n/, "$_[0]\n\n\n\n\n\n\n";
263 my $whendone = "open";
264 my $severity = $gDefaultSeverity;
265 (my $pkglist = $stuff[4]) =~ s/[,\s]+/,/g;
268 $whendone = "forwarded" if length $stuff[7];
269 $whendone = "done" if length $stuff[6];
270 $severity = $stuff[9] if length $stuff[9];
272 my $k = sprintf "%s %d %d %s [%s] %s %s\n",
273 $pkglist, $ref, $stuff[1], $whendone, $stuff[0],
274 $severity, $stuff[5];
276 update_realtime("$gSpoolDir/index.db.realtime", $ref, $k);
283 if (!open(AP,">>$file")) {
284 print DEBUG "failed open log<\n";
285 print DEBUG "failed open log err $!<\n";
286 &quit("opening $file (appendfile): $!");
288 print(AP @_) || &quit("writing $file (appendfile): $!");
289 close(AP) || &quit("closing $file (appendfile): $!");
294 my $type = $entity->effective_type;
295 if ($type eq 'text/plain' or
296 ($type =~ m#text/# and $type ne 'text/html') or
297 $type eq 'application/pgp') {
298 return $entity->bodyhandle;
299 } elsif ($type eq 'multipart/alternative') {
300 # RFC 2046 says we should use the last part we recognize.
301 for my $part (reverse $entity->parts) {
302 my $ret = getmailbody($part);
306 # For other multipart types, we just pretend they're
307 # multipart/mixed and run through in order.
308 for my $part ($entity->parts) {
309 my $ret = getmailbody($part);
318 map { s/^([\01-\07\030])/\030$1/gm } @log;
323 @severities= grep { not exists $gObsoleteSeverities{$_} } @gSeverityList;
324 @showseverities= @severities;
325 grep ($_= $_ eq '' ? $gDefaultSeverity : $_, @showseverities);
326 @strongseverities= @gStrongSeverities;
327 %displayshowseverities= %gSeverityDisplay;