1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later
3 # version at your option.
4 # See the file README and COPYING for more information.
6 # [Other people have contributed to this file; their copyrights should
8 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
10 package Debbugs::Status;
14 Debbugs::Status -- Routines for dealing with summary and status files
23 This module is a replacement for the parts of errorlib.pl which write
24 and read status and summary files.
26 It also contains generic routines for returning information about the
27 status of a particular bug
35 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
36 use base qw(Exporter);
38 use Params::Validate qw(validate_with :types);
39 use Debbugs::Common qw(:util :lock :quit :misc);
40 use Debbugs::Config qw(:config);
41 use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522);
42 use Debbugs::Packages qw(makesourceversions getversions get_versions binarytosource);
43 use Debbugs::Versions;
44 use Debbugs::Versions::Dpkg;
47 use List::Util qw(min max);
52 $DEBUG = 0 unless defined $DEBUG;
55 %EXPORT_TAGS = (status => [qw(splitpackages get_bug_status buggy bug_archiveable),
56 qw(isstrongseverity bug_presence),
58 read => [qw(readbug read_bug lockreadbug)],
59 write => [qw(writebug makestatus unlockwritebug)],
60 versions => [qw(addfoundversions addfixedversions),
61 qw(removefoundversions removefixedversions)
63 hook => [qw(bughook bughook_archive)],
66 Exporter::export_ok_tags(qw(status read write versions hook));
67 $EXPORT_TAGS{all} = [@EXPORT_OK];
73 readbug($bug_num,$location)
76 Reads a summary file from the archive given a bug number and a bug
77 location. Valid locations are those understood by L</getbugcomponent>
82 my %fields = (originator => 'submitter',
85 msgid => 'message-id',
86 'package' => 'package',
89 forwarded => 'forwarded-to',
90 mergedwith => 'merged-with',
91 severity => 'severity',
93 found_versions => 'found-in',
94 found_date => 'found-date',
95 fixed_versions => 'fixed-in',
96 fixed_date => 'fixed-date',
98 blockedby => 'blocked-by',
101 # Fields which need to be RFC1522-decoded in format versions earlier than 3.
102 my @rfc1522_fields = qw(originator subject done forwarded owner);
105 return read_bug(bug => $_[0],
106 (@_ > 1)?(location => $_[1]):()
112 read_bug(bug => $bug_num,
113 location => 'archive',
115 read_bug(summary => 'path/to/bugnum.summary');
118 A more complete function than readbug; it enables you to pass a full
119 path to the summary file instead of the bug number and/or location.
125 =item bug -- the bug number
127 =item location -- optional location which is passed to getbugcomponent
129 =item summary -- complete path to the .summary file which will be read
133 One of C<bug> or C<summary> must be passed. This function will return
134 undef on failure, and will die if improper arguments are passed.
142 my %param = validate_with(params => \@_,
143 spec => {bug => {type => SCALAR,
147 # negative bugnumbers
150 location => {type => SCALAR|UNDEF,
153 summary => {type => SCALAR,
158 die "One of bug or summary must be passed to read_bug"
159 if not exists $param{bug} and not exists $param{summary};
161 if (not defined $param{summary}) {
162 my ($lref, $location) = @param{qw(bug location)};
163 if (not defined $location) {
164 $location = getbuglocation($lref,'summary');
165 return undef if not defined $location;
167 $status = getbugcomponent($lref, 'summary', $location);
168 return undef unless defined $status;
171 $status = $param{summary};
173 my $status_fh = new IO::File $status, 'r' or
174 warn "Unable to open $status for reading: $!" and return undef;
181 while (<$status_fh>) {
184 $version = $1 if /^Format-Version: ([0-9]+)/i;
187 # Version 3 is the latest format version currently supported.
188 return undef if $version > 3;
190 my %namemap = reverse %fields;
191 for my $line (@lines) {
192 if ($line =~ /(\S+?): (.*)/) {
193 my ($name, $value) = (lc $1, $2);
194 $data{$namemap{$name}} = $value if exists $namemap{$name};
197 for my $field (keys %fields) {
198 $data{$field} = '' unless exists $data{$field};
201 $data{severity} = $config{default_severity} if $data{severity} eq '';
202 for my $field (qw(found_versions fixed_versions found_date fixed_date)) {
203 $data{$field} = [split ' ', $data{$field}];
205 for my $field (qw(found fixed)) {
206 # create the found/fixed hashes which indicate when a
207 # particular version was marked found or marked fixed.
208 @{$data{$field}}{@{$data{"${field}_versions"}}} =
209 (('') x (@{$data{"${field}_date"}} - @{$data{"${field}_versions"}}),
210 @{$data{"${field}_date"}});
214 for my $field (@rfc1522_fields) {
215 $data{$field} = decode_rfc1522($data{$field});
224 lockreadbug($bug_num,$location)
226 Performs a filelock, then reads the bug; the bug is unlocked if the
227 return is undefined, otherwise, you need to call unfilelock or
230 See readbug above for information on what this returns
235 my ($lref, $location) = @_;
236 &filelock("lock/$lref");
237 my $data = read_bug(bug => $lref, location => $location);
238 &unfilelock unless defined $data;
242 my @v1fieldorder = qw(originator date subject msgid package
243 keywords done forwarded mergedwith severity);
247 my $content = makestatus($status,$version)
248 my $content = makestatus($status);
250 Creates the content for a status file based on the $status hashref
253 Really only useful for writebug
255 Currently defaults to version 2 (non-encoded rfc1522 names) but will
256 eventually default to version 3. If you care, you should specify a
262 my ($data,$version) = @_;
263 $version = 2 unless defined $version;
267 my %newdata = %$data;
268 for my $field (qw(found fixed)) {
269 if (exists $newdata{$field}) {
270 $newdata{"${field}_date"} =
271 [map {$newdata{$field}{$_}||''} keys %{$newdata{$field}}];
275 for my $field (qw(found_versions fixed_versions found_date fixed_date)) {
276 $newdata{$field} = join ' ', @{$newdata{$field}||[]};
280 for my $field (@rfc1522_fields) {
281 $newdata{$field} = encode_rfc1522($newdata{$field});
286 for my $field (@v1fieldorder) {
287 if (exists $newdata{$field} and defined $newdata{$field}) {
288 $contents .= "$newdata{$field}\n";
293 } elsif ($version == 2 or $version == 3) {
294 # Version 2 or 3. Add a file format version number for the sake of
295 # further extensibility in the future.
296 $contents .= "Format-Version: $version\n";
297 for my $field (keys %fields) {
298 if (exists $newdata{$field} and defined $newdata{$field}
299 and $newdata{$field} ne '') {
300 # Output field names in proper case, e.g. 'Merged-With'.
301 my $properfield = $fields{$field};
302 $properfield =~ s/(?:^|(?<=-))([a-z])/\u$1/g;
303 $contents .= "$properfield: $newdata{$field}\n";
313 writebug($bug_num,$status,$location,$minversion,$disablebughook)
315 Writes the bug status and summary files out.
317 Skips writting out a status file if minversion is 2
319 Does not call bughook if disablebughook is true.
324 my ($ref, $data, $location, $minversion, $disablebughook) = @_;
327 my %outputs = (1 => 'status', 2 => 'summary');
328 for my $version (keys %outputs) {
329 next if defined $minversion and $version < $minversion;
330 my $status = getbugcomponent($ref, $outputs{$version}, $location);
331 &quit("can't find location for $ref") unless defined $status;
332 open(S,"> $status.new") || &quit("opening $status.new: $!");
333 print(S makestatus($data, $version)) ||
334 &quit("writing $status.new: $!");
335 close(S) || &quit("closing $status.new: $!");
341 rename("$status.new",$status) || &quit("installing new $status: $!");
344 # $disablebughook is a bit of a hack to let format migration scripts use
345 # this function rather than having to duplicate it themselves.
346 &bughook($change,$ref,$data) unless $disablebughook;
349 =head2 unlockwritebug
351 unlockwritebug($bug_num,$status,$location,$minversion,$disablebughook);
353 Writes a bug, then calls unfilelock; see writebug for what these
365 The following functions are exported with the :versions tag
367 =head2 addfoundversions
369 addfoundversions($status,$package,$version,$isbinary);
376 sub addfoundversions {
380 my $isbinary = shift;
381 return unless defined $version;
382 undef $package if $package =~ m[(?:\s|/)];
383 my $source = $package;
385 if (defined $package and $isbinary) {
386 my @srcinfo = binarytosource($package, $version, undef);
388 # We know the source package(s). Use a fully-qualified version.
389 addfoundversions($data, $_->[0], $_->[1], '') foreach @srcinfo;
392 # Otherwise, an unqualified version will have to do.
396 # Strip off various kinds of brain-damage.
398 $version =~ s/ *\(.*\)//;
399 $version =~ s/ +[A-Za-z].*//;
401 foreach my $ver (split /[,\s]+/, $version) {
402 my $sver = defined($source) ? "$source/$ver" : '';
403 unless (grep { $_ eq $ver or $_ eq $sver } @{$data->{found_versions}}) {
404 push @{$data->{found_versions}}, defined($source) ? $sver : $ver;
406 @{$data->{fixed_versions}} =
407 grep { $_ ne $ver and $_ ne $sver } @{$data->{fixed_versions}};
411 =head2 removefoundversions
413 removefoundversions($data,$package,$versiontoremove)
415 Removes found versions from $data
417 If a version is fully qualified (contains /) only versions matching
418 exactly are removed. Otherwise, all versions matching the version
421 Currently $package and $isbinary are entirely ignored, but accepted
422 for backwards compatibilty.
426 sub removefoundversions {
430 my $isbinary = shift;
431 return unless defined $version;
433 foreach my $ver (split /[,\s]+/, $version) {
435 # fully qualified version
436 @{$data->{found_versions}} =
438 @{$data->{found_versions}};
441 # non qualified version; delete all matchers
442 @{$data->{found_versions}} =
443 grep {$_ !~ m[(?:^|/)\Q$ver\E$]}
444 @{$data->{found_versions}};
450 sub addfixedversions {
454 my $isbinary = shift;
455 return unless defined $version;
456 undef $package if defined $package and $package =~ m[(?:\s|/)];
457 my $source = $package;
459 if (defined $package and $isbinary) {
460 my @srcinfo = binarytosource($package, $version, undef);
462 # We know the source package(s). Use a fully-qualified version.
463 addfixedversions($data, $_->[0], $_->[1], '') foreach @srcinfo;
466 # Otherwise, an unqualified version will have to do.
470 # Strip off various kinds of brain-damage.
472 $version =~ s/ *\(.*\)//;
473 $version =~ s/ +[A-Za-z].*//;
475 foreach my $ver (split /[,\s]+/, $version) {
476 my $sver = defined($source) ? "$source/$ver" : '';
477 unless (grep { $_ eq $ver or $_ eq $sver } @{$data->{fixed_versions}}) {
478 push @{$data->{fixed_versions}}, defined($source) ? $sver : $ver;
480 @{$data->{found_versions}} =
481 grep { $_ ne $ver and $_ ne $sver } @{$data->{found_versions}};
485 sub removefixedversions {
489 my $isbinary = shift;
490 return unless defined $version;
491 undef $package if $package =~ m[(?:\s|/)];
492 my $source = $package;
494 if (defined $package and $isbinary) {
495 my @srcinfo = binarytosource($package, $version, undef);
497 # We know the source package(s). Use a fully-qualified version.
498 removefixedversions($data, $_->[0], $_->[1], '') foreach @srcinfo;
501 # Otherwise, an unqualified version will have to do.
505 foreach my $ver (split /[,\s]+/, $version) {
506 my $sver = defined($source) ? "$source/$ver" : '';
507 @{$data->{fixed_versions}} =
508 grep { $_ ne $ver and $_ ne $sver } @{$data->{fixed_versions}};
518 Split a package string from the status file into a list of package names.
524 return unless defined $pkgs;
525 return map lc, split /[ \t?,()]+/, $pkgs;
529 =head2 bug_archiveable
531 bug_archiveable(bug => $bug_num);
537 =item bug -- bug number (required)
539 =item status -- Status hashref returned by read_bug or get_bug_status (optional)
541 =item version -- Debbugs::Version information (optional)
543 =item days_until -- return days until the bug can be archived
547 Returns 1 if the bug can be archived
548 Returns 0 if the bug cannot be archived
550 If days_until is true, returns the number of days until the bug can be
551 archived, -1 if it cannot be archived. 0 means that the bug can be
552 archived the next time the archiver runs.
554 Returns undef on failure.
558 # This will eventually need to be fixed before we start using mod_perl
559 our $version_cache = {};
561 my %param = validate_with(params => \@_,
562 spec => {bug => {type => SCALAR,
565 status => {type => HASHREF,
568 days_until => {type => BOOLEAN,
573 # This is what we return if the bug cannot be archived.
574 my $cannot_archive = $param{days_until}?-1:0;
575 # read the status information
576 my $status = $param{status};
577 if (not exists $param{status} or not defined $status) {
578 $status = read_bug(bug=>$param{bug});
579 return undef if not defined $status;
581 # Bugs can be archived if they are
583 return $cannot_archive if not defined $status->{done} or not length $status->{done};
584 # If we just are checking if the bug can be archived, we'll not even bother
585 # checking the versioning information if the bug has been -done for less than 28 days.
586 if (not $param{days_until} and $config{remove_age} >
587 -M getbugcomponent($param{ref},'log')
589 return $cannot_archive;
591 # At this point, we have to get the versioning information for this bug.
592 # We examine the set of distribution tags. If a bug has no distribution
593 # tags set, we assume a default set, otherwise we use the tags the bug
596 # There must be fixed_versions for us to look at the versioning
598 my $min_fixed_time = time;
599 my $min_archive_days = 0;
600 if (@{$status->{fixed_versions}}) {
602 @dist_tags{@{$config{removal_distribution_tags}}} =
603 (1) x @{$config{removal_distribution_tags}};
605 @dists{@{$config{removal_default_distribution_tags}}} =
606 (1) x @{$config{removal_default_distribution_tags}};
607 for my $tag (split ' ', ($status->{tags}||'')) {
608 next unless $dist_tags{$tag};
612 my @sourceversions = get_versions(package => $status->{package},
613 dist => [keys %dists],
616 @source_versions{@sourceversions} = (1) x @sourceversions;
617 # If the bug has not been fixed in the versions actually
618 # distributed, then it cannot be archived.
619 if ('found' eq max_buggy(bug => $param{bug},
620 sourceversions => [keys %source_versions],
621 found => $status->{found_versions},
622 fixed => $status->{fixed_versions},
623 version_cache => $version_cache,
624 package => $status->{package},
626 return $cannot_archive;
628 # Since the bug has at least been fixed in the architectures
629 # that matters, we check to see how long it has been fixed.
631 # To do this, we order the times from most recent to oldest;
632 # when we come to the first found version, we stop.
633 # If we run out of versions, we only report the time of the
635 my %time_versions = get_versions(package => $status->{package},
636 dist => [keys %dists],
640 for my $version (sort {$time_versions{$b} <=> $time_versions{$a}} keys %time_versions) {
641 my $buggy = buggy(bug => $param{bug},
643 found => $status->{found_versions},
644 fixed => $status->{fixed_versions},
645 version_cache => $version_cache,
646 package => $status->{package},
648 last if $buggy eq 'found';
649 $min_fixed_time = min($time_versions{$version},$min_fixed_time);
651 $min_archive_days = max($min_archive_days,ceil((time - $min_fixed_time)/(60*60*24)));
653 # 6. at least 28 days have passed since the last action has occured or the bug was closed
654 my $age = ceil($config{remove_age} - -M getbugcomponent($param{bug},'log'));
655 if ($age > 0 or $min_archive_days > 0) {
656 return $param{days_until}?max($age,$min_archive_days):0;
659 return $param{days_until}?0:1;
664 =head2 get_bug_status
666 my $status = get_bug_status(bug => $nnn);
668 my $status = get_bug_status($bug_num)
674 =item bug -- scalar bug number
676 =item status -- optional hashref of bug status as returned by readbug
677 (can be passed to avoid rereading the bug information)
679 =item bug_index -- optional tied index of bug status infomration;
680 currently not correctly implemented.
682 =item version -- optional version(s) to check package status at
684 =item dist -- optional distribution(s) to check package status at
686 =item arch -- optional architecture(s) to check package status at
688 =item usertags -- optional hashref of usertags
690 =item sourceversion -- optional arrayref of source/version; overrides
691 dist, arch, and version. [The entries in this array must be in the
692 "source/version" format.] Eventually this can be used to for caching.
696 Note: Currently the version information is cached; this needs to be
697 changed before using this function in long lived programs.
705 my %param = validate_with(params => \@_,
706 spec => {bug => {type => SCALAR,
709 status => {type => HASHREF,
712 bug_index => {type => OBJECT,
715 version => {type => SCALAR|ARRAYREF,
718 dist => {type => SCALAR|ARRAYREF,
721 arch => {type => SCALAR|ARRAYREF,
724 usertags => {type => HASHREF,
727 sourceversions => {type => ARRAYREF,
734 if (defined $param{bug_index} and
735 exists $param{bug_index}{$param{bug}}) {
736 %status = %{ $param{bug_index}{$param{bug}} };
737 $status{pending} = $status{ status };
738 $status{id} = $param{bug};
741 if (defined $param{status}) {
742 %status = %{$param{status}};
745 my $location = getbuglocation($param{bug}, 'summary');
746 return {} if not length $location;
747 %status = %{ readbug( $param{bug}, $location ) };
749 $status{id} = $param{bug};
751 if (defined $param{usertags}{$param{bug}}) {
752 $status{keywords} = "" unless defined $status{keywords};
753 $status{keywords} .= " " unless $status{keywords} eq "";
754 $status{keywords} .= join(" ", @{$param{usertags}{$param{bug}}});
756 $status{tags} = $status{keywords};
757 my %tags = map { $_ => 1 } split ' ', $status{tags};
759 $status{"package"} =~ s/\s*$//;
760 $status{"package"} = 'unknown' if ($status{"package"} eq '');
761 $status{"severity"} = 'normal' if ($status{"severity"} eq '');
763 $status{"pending"} = 'pending';
764 $status{"pending"} = 'forwarded' if (length($status{"forwarded"}));
765 $status{"pending"} = 'pending-fixed' if ($tags{pending});
766 $status{"pending"} = 'fixed' if ($tags{fixed});
769 my $presence = bug_presence(map{(exists $param{$_})?($_,$param{$_}):()}
770 qw(bug sourceversions arch dist version found fixed package)
772 if (defined $presence) {
773 if ($presence eq 'fixed') {
774 $status{pending} = 'done';
776 elsif ($presence eq 'absent') {
777 $status{pending} = 'absent';
785 my $precence = bug_presence(bug => nnn,
789 Returns 'found', 'absent', 'fixed' or undef based on whether the bug
790 is found, absent, fixed, or no information is available in the
791 distribution (dist) and/or architecture (arch) specified.
798 =item bug -- scalar bug number
800 =item status -- optional hashref of bug status as returned by readbug
801 (can be passed to avoid rereading the bug information)
803 =item bug_index -- optional tied index of bug status infomration;
804 currently not correctly implemented.
806 =item version -- optional version to check package status at
808 =item dist -- optional distribution to check package status at
810 =item arch -- optional architecture to check package status at
812 =item sourceversion -- optional arrayref of source/version; overrides
813 dist, arch, and version. [The entries in this array must be in the
814 "source/version" format.] Eventually this can be used to for caching.
821 my %param = validate_with(params => \@_,
822 spec => {bug => {type => SCALAR,
825 status => {type => HASHREF,
828 version => {type => SCALAR|ARRAYREF,
831 dist => {type => SCALAR|ARRAYREF,
834 arch => {type => SCALAR|ARRAYREF,
837 sourceversions => {type => ARRAYREF,
843 if (defined $param{status}) {
844 %status = %{$param{status}};
847 my $location = getbuglocation($param{bug}, 'summary');
848 return {} if not length $location;
849 %status = %{ readbug( $param{bug}, $location ) };
853 if (not exists $param{sourceversions}) {
855 if (defined $param{version}) {
856 foreach my $arch (make_list($param{arch})) {
857 my @temp = makesourceversions($status{package},
859 make_list($param{version})
861 @sourceversions{@temp} = (1) x @temp;
863 } elsif (defined $param{dist}) {
864 foreach my $arch (make_list($param{arch})) {
866 foreach my $dist (make_list($param{dist})) {
867 push @versions, getversions($status{package}, $dist, $arch);
869 my @temp = makesourceversions($status{package},
873 @sourceversions{@temp} = (1) x @temp;
877 # TODO: This should probably be handled further out for efficiency and
878 # for more ease of distinguishing between pkg= and src= queries.
879 @sourceversions = keys %sourceversions;
882 @sourceversions = @{$param{sourceversions}};
884 my $maxbuggy = 'undef';
885 if (@sourceversions) {
886 $maxbuggy = max_buggy(bug => $param{bug},
887 sourceversions => \@sourceversions,
888 found => $status{found_versions},
889 fixed => $status{fixed_versions},
890 package => $status{package},
891 version_cache => $version_cache,
894 elsif (defined $param{dist}) {
897 if (length($status{done}) and
898 (not @sourceversions or not @{$status{fixed_versions}})) {
913 =item bug -- scalar bug number
915 =item sourceversion -- optional arrayref of source/version; overrides
916 dist, arch, and version. [The entries in this array must be in the
917 "source/version" format.] Eventually this can be used to for caching.
921 Note: Currently the version information is cached; this needs to be
922 changed before using this function in long lived programs.
927 my %param = validate_with(params => \@_,
928 spec => {bug => {type => SCALAR,
931 sourceversions => {type => ARRAYREF,
934 found => {type => ARRAYREF,
937 fixed => {type => ARRAYREF,
940 package => {type => SCALAR,
942 version_cache => {type => HASHREF,
947 # Resolve bugginess states (we might be looking at multiple
948 # architectures, say). Found wins, then fixed, then absent.
949 my $maxbuggy = 'absent';
950 for my $version (@{$param{sourceversions}}) {
951 my $buggy = buggy(bug => $param{bug},
953 found => $param{found},
954 fixed => $param{fixed},
955 version_cache => $param{version_cache},
956 package => $param{package},
958 if ($buggy eq 'found') {
960 } elsif ($buggy eq 'fixed') {
977 Returns the output of Debbugs::Versions::buggy for a particular
978 package, version and found/fixed set. Automatically turns found, fixed
979 and version into source/version strings.
981 Caching can be had by using the version_cache, but no attempt to check
982 to see if the on disk information is more recent than the cache is
983 made. [This will need to be fixed for long-lived processes.]
988 my %param = validate_with(params => \@_,
989 spec => {bug => {type => SCALAR,
992 found => {type => ARRAYREF,
995 fixed => {type => ARRAYREF,
998 version_cache => {type => HASHREF,
1001 package => {type => SCALAR,
1003 version => {type => SCALAR,
1007 my @found = @{$param{found}};
1008 my @fixed = @{$param{fixed}};
1009 if (grep {$_ !~ m{/}} (@{$param{found}}, @{$param{fixed}})) {
1010 # We have non-source version versions
1011 @found = makesourceversions($param{package},undef,
1014 @fixed = makesourceversions($param{package},undef,
1018 if ($param{version} !~ m{/}) {
1019 $param{version} = makesourceversions($param{package},undef,
1023 # Figure out which source packages we need
1025 @sources{map {m{(.+)/}; $1} @found} = (1) x @found;
1026 @sources{map {m{(.+)/}; $1} @fixed} = (1) x @fixed;
1027 @sources{map {m{(.+)/}; $1} $param{version}} = 1;
1029 if (not defined $param{version_cache} or
1030 not exists $param{version_cache}{join(',',sort keys %sources)}) {
1031 $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp);
1032 foreach my $source (keys %sources) {
1033 my $srchash = substr $source, 0, 1;
1034 my $version_fh = new IO::File "$config{version_packages_dir}/$srchash/$source", 'r' or
1035 warn "Unable to open $config{version_packages_dir}/$srchash/$source: $!" and next;
1036 $version->load($version_fh);
1038 if (defined $param{version_cache}) {
1039 $param{version_cache}{join(',',sort keys %sources)} = $version;
1043 $version = $param{version_cache}{join(',',sort keys %sources)};
1045 return $version->buggy($param{version},\@found,\@fixed);
1048 sub isstrongseverity {
1049 my $severity = shift;
1050 $severity = $config{default_severity} if $severity eq '';
1051 return grep { $_ eq $severity } @{$config{strong_severities}};
1055 =head1 PRIVATE FUNCTIONS
1059 sub update_realtime {
1060 my ($file, $bug, $new) = @_;
1062 # update realtime index.db
1064 open(IDXDB, "<$file") or die "Couldn't open $file";
1065 open(IDXNEW, ">$file.new");
1069 while($line = <IDXDB>) {
1070 @line = split /\s/, $line;
1071 last if ($line[1] >= $bug);
1076 if ($new eq "NOCHANGE") {
1077 print IDXNEW $line if ($line ne "" and $line[1] == $bug);
1078 } elsif ($new eq "REMOVE") {
1083 if (defined $line and $line ne "" and @line and $line[1] > $bug) {
1088 print IDXNEW while(<IDXDB>);
1093 rename("$file.new", $file);
1098 sub bughook_archive {
1100 &filelock("debbugs.trace.lock");
1101 &appendfile("debbugs.trace","archive $ref\n");
1102 my $line = update_realtime(
1103 "$config{spool_dir}/index.db.realtime",
1106 update_realtime("$config{spool_dir}/index.archive.realtime",
1112 my ( $type, $ref, $data ) = @_;
1113 &filelock("debbugs.trace.lock");
1115 &appendfile("debbugs.trace","$type $ref\n",makestatus($data, 1));
1117 my $whendone = "open";
1118 my $severity = $config{default_severity};
1119 (my $pkglist = $data->{package}) =~ s/[,\s]+/,/g;
1120 $pkglist =~ s/^,+//;
1121 $pkglist =~ s/,+$//;
1122 $whendone = "forwarded" if defined $data->{forwarded} and length $data->{forwarded};
1123 $whendone = "done" if defined $data->{done} and length $data->{done};
1124 $severity = $data->{severity} if length $data->{severity};
1126 my $k = sprintf "%s %d %d %s [%s] %s %s\n",
1127 $pkglist, $ref, $data->{date}, $whendone,
1128 $data->{originator}, $severity, $data->{keywords};
1130 update_realtime("$config{spool_dir}/index.db.realtime", $ref, $k);