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 lockreadbugmerge)],
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',
99 unarchived => 'unarchived',
102 # Fields which need to be RFC1522-decoded in format versions earlier than 3.
103 my @rfc1522_fields = qw(originator subject done forwarded owner);
106 return read_bug(bug => $_[0],
107 (@_ > 1)?(location => $_[1]):()
113 read_bug(bug => $bug_num,
114 location => 'archive',
116 read_bug(summary => 'path/to/bugnum.summary');
119 A more complete function than readbug; it enables you to pass a full
120 path to the summary file instead of the bug number and/or location.
126 =item bug -- the bug number
128 =item location -- optional location which is passed to getbugcomponent
130 =item summary -- complete path to the .summary file which will be read
134 One of C<bug> or C<summary> must be passed. This function will return
135 undef on failure, and will die if improper arguments are passed.
143 my %param = validate_with(params => \@_,
144 spec => {bug => {type => SCALAR,
148 # negative bugnumbers
151 location => {type => SCALAR|UNDEF,
154 summary => {type => SCALAR,
159 die "One of bug or summary must be passed to read_bug"
160 if not exists $param{bug} and not exists $param{summary};
164 if (not defined $param{summary}) {
166 ($lref,$location) = @param{qw(bug location)};
167 if (not defined $location) {
168 $location = getbuglocation($lref,'summary');
169 return undef if not defined $location;
171 $status = getbugcomponent($lref, 'summary', $location);
172 $log = getbugcomponent($lref, 'log' , $location);
173 return undef unless defined $status;
176 $status = $param{summary};
178 $log =~ s/\.summary$/.log/;
179 ($location) = $status =~ m/(db-h|db|archive)/;
181 my $status_fh = new IO::File $status, 'r' or
182 warn "Unable to open $status for reading: $!" and return undef;
189 while (<$status_fh>) {
192 $version = $1 if /^Format-Version: ([0-9]+)/i;
195 # Version 3 is the latest format version currently supported.
197 warn "Unsupported status version '$version'";
201 my %namemap = reverse %fields;
202 for my $line (@lines) {
203 if ($line =~ /(\S+?): (.*)/) {
204 my ($name, $value) = (lc $1, $2);
205 $data{$namemap{$name}} = $value if exists $namemap{$name};
208 for my $field (keys %fields) {
209 $data{$field} = '' unless exists $data{$field};
212 $data{severity} = $config{default_severity} if $data{severity} eq '';
213 for my $field (qw(found_versions fixed_versions found_date fixed_date)) {
214 $data{$field} = [split ' ', $data{$field}];
216 for my $field (qw(found fixed)) {
217 # create the found/fixed hashes which indicate when a
218 # particular version was marked found or marked fixed.
219 @{$data{$field}}{@{$data{"${field}_versions"}}} =
220 (('') x (@{$data{"${field}_date"}} - @{$data{"${field}_versions"}}),
221 @{$data{"${field}_date"}});
225 for my $field (@rfc1522_fields) {
226 $data{$field} = decode_rfc1522($data{$field});
229 # Add log last modified time
230 $data{log_modified} = (stat($log))[9];
231 $data{location} = $location;
232 $data{bug_num} = $param{bug};
239 lockreadbug($bug_num,$location)
241 Performs a filelock, then reads the bug; the bug is unlocked if the
242 return is undefined, otherwise, you need to call unfilelock or
245 See readbug above for information on what this returns
250 my ($lref, $location) = @_;
251 &filelock("lock/$lref");
252 my $data = read_bug(bug => $lref, location => $location);
253 &unfilelock unless defined $data;
257 =head2 lockreadbugmerge
259 my ($locks, $data) = lockreadbugmerge($bug_num,$location);
261 Performs a filelock, then reads the bug. If the bug is merged, locks
262 the merge lock. Returns a list of the number of locks and the bug
267 sub lockreadbugmerge {
268 my ($bug_num,$location) = @_;
269 my $data = lockreadbug(@_);
270 if (not defined $data) {
273 if (not length $data->{mergedwith}) {
277 filelock('lock/merge');
278 $data = lockreadbug(@_);
279 if (not defined $data) {
287 my @v1fieldorder = qw(originator date subject msgid package
288 keywords done forwarded mergedwith severity);
292 my $content = makestatus($status,$version)
293 my $content = makestatus($status);
295 Creates the content for a status file based on the $status hashref
298 Really only useful for writebug
300 Currently defaults to version 2 (non-encoded rfc1522 names) but will
301 eventually default to version 3. If you care, you should specify a
307 my ($data,$version) = @_;
308 $version = 2 unless defined $version;
312 my %newdata = %$data;
313 for my $field (qw(found fixed)) {
314 if (exists $newdata{$field}) {
315 $newdata{"${field}_date"} =
316 [map {$newdata{$field}{$_}||''} keys %{$newdata{$field}}];
320 for my $field (qw(found_versions fixed_versions found_date fixed_date)) {
321 $newdata{$field} = join ' ', @{$newdata{$field}||[]};
325 for my $field (@rfc1522_fields) {
326 $newdata{$field} = encode_rfc1522($newdata{$field});
331 for my $field (@v1fieldorder) {
332 if (exists $newdata{$field} and defined $newdata{$field}) {
333 $contents .= "$newdata{$field}\n";
338 } elsif ($version == 2 or $version == 3) {
339 # Version 2 or 3. Add a file format version number for the sake of
340 # further extensibility in the future.
341 $contents .= "Format-Version: $version\n";
342 for my $field (keys %fields) {
343 if (exists $newdata{$field} and defined $newdata{$field}
344 and $newdata{$field} ne '') {
345 # Output field names in proper case, e.g. 'Merged-With'.
346 my $properfield = $fields{$field};
347 $properfield =~ s/(?:^|(?<=-))([a-z])/\u$1/g;
348 $contents .= "$properfield: $newdata{$field}\n";
358 writebug($bug_num,$status,$location,$minversion,$disablebughook)
360 Writes the bug status and summary files out.
362 Skips writting out a status file if minversion is 2
364 Does not call bughook if disablebughook is true.
369 my ($ref, $data, $location, $minversion, $disablebughook) = @_;
372 my %outputs = (1 => 'status', 2 => 'summary');
373 for my $version (keys %outputs) {
374 next if defined $minversion and $version < $minversion;
375 my $status = getbugcomponent($ref, $outputs{$version}, $location);
376 die "can't find location for $ref" unless defined $status;
377 open(S,"> $status.new") || die "opening $status.new: $!";
378 print(S makestatus($data, $version)) ||
379 die "writing $status.new: $!";
380 close(S) || die "closing $status.new: $!";
386 rename("$status.new",$status) || die "installing new $status: $!";
389 # $disablebughook is a bit of a hack to let format migration scripts use
390 # this function rather than having to duplicate it themselves.
391 &bughook($change,$ref,$data) unless $disablebughook;
394 =head2 unlockwritebug
396 unlockwritebug($bug_num,$status,$location,$minversion,$disablebughook);
398 Writes a bug, then calls unfilelock; see writebug for what these
410 The following functions are exported with the :versions tag
412 =head2 addfoundversions
414 addfoundversions($status,$package,$version,$isbinary);
421 sub addfoundversions {
425 my $isbinary = shift;
426 return unless defined $version;
427 undef $package if $package =~ m[(?:\s|/)];
428 my $source = $package;
430 if (defined $package and $isbinary) {
431 my @srcinfo = binarytosource($package, $version, undef);
433 # We know the source package(s). Use a fully-qualified version.
434 addfoundversions($data, $_->[0], $_->[1], '') foreach @srcinfo;
437 # Otherwise, an unqualified version will have to do.
441 # Strip off various kinds of brain-damage.
443 $version =~ s/ *\(.*\)//;
444 $version =~ s/ +[A-Za-z].*//;
446 foreach my $ver (split /[,\s]+/, $version) {
447 my $sver = defined($source) ? "$source/$ver" : '';
448 unless (grep { $_ eq $ver or $_ eq $sver } @{$data->{found_versions}}) {
449 push @{$data->{found_versions}}, defined($source) ? $sver : $ver;
451 @{$data->{fixed_versions}} =
452 grep { $_ ne $ver and $_ ne $sver } @{$data->{fixed_versions}};
456 =head2 removefoundversions
458 removefoundversions($data,$package,$versiontoremove)
460 Removes found versions from $data
462 If a version is fully qualified (contains /) only versions matching
463 exactly are removed. Otherwise, all versions matching the version
466 Currently $package and $isbinary are entirely ignored, but accepted
467 for backwards compatibilty.
471 sub removefoundversions {
475 my $isbinary = shift;
476 return unless defined $version;
478 foreach my $ver (split /[,\s]+/, $version) {
480 # fully qualified version
481 @{$data->{found_versions}} =
483 @{$data->{found_versions}};
486 # non qualified version; delete all matchers
487 @{$data->{found_versions}} =
488 grep {$_ !~ m[(?:^|/)\Q$ver\E$]}
489 @{$data->{found_versions}};
495 sub addfixedversions {
499 my $isbinary = shift;
500 return unless defined $version;
501 undef $package if defined $package and $package =~ m[(?:\s|/)];
502 my $source = $package;
504 if (defined $package and $isbinary) {
505 my @srcinfo = binarytosource($package, $version, undef);
507 # We know the source package(s). Use a fully-qualified version.
508 addfixedversions($data, $_->[0], $_->[1], '') foreach @srcinfo;
511 # Otherwise, an unqualified version will have to do.
515 # Strip off various kinds of brain-damage.
517 $version =~ s/ *\(.*\)//;
518 $version =~ s/ +[A-Za-z].*//;
520 foreach my $ver (split /[,\s]+/, $version) {
521 my $sver = defined($source) ? "$source/$ver" : '';
522 unless (grep { $_ eq $ver or $_ eq $sver } @{$data->{fixed_versions}}) {
523 push @{$data->{fixed_versions}}, defined($source) ? $sver : $ver;
525 @{$data->{found_versions}} =
526 grep { $_ ne $ver and $_ ne $sver } @{$data->{found_versions}};
530 sub removefixedversions {
534 my $isbinary = shift;
535 return unless defined $version;
537 foreach my $ver (split /[,\s]+/, $version) {
539 # fully qualified version
540 @{$data->{fixed_versions}} =
542 @{$data->{fixed_versions}};
545 # non qualified version; delete all matchers
546 @{$data->{fixed_versions}} =
547 grep {$_ !~ m[(?:^|/)\Q$ver\E$]}
548 @{$data->{fixed_versions}};
559 Split a package string from the status file into a list of package names.
565 return unless defined $pkgs;
566 return map lc, split /[ \t?,()]+/, $pkgs;
570 =head2 bug_archiveable
572 bug_archiveable(bug => $bug_num);
578 =item bug -- bug number (required)
580 =item status -- Status hashref returned by read_bug or get_bug_status (optional)
582 =item version -- Debbugs::Version information (optional)
584 =item days_until -- return days until the bug can be archived
588 Returns 1 if the bug can be archived
589 Returns 0 if the bug cannot be archived
591 If days_until is true, returns the number of days until the bug can be
592 archived, -1 if it cannot be archived. 0 means that the bug can be
593 archived the next time the archiver runs.
595 Returns undef on failure.
599 # This will eventually need to be fixed before we start using mod_perl
600 our $version_cache = {};
602 my %param = validate_with(params => \@_,
603 spec => {bug => {type => SCALAR,
606 status => {type => HASHREF,
609 days_until => {type => BOOLEAN,
612 ignore_time => {type => BOOLEAN,
617 # This is what we return if the bug cannot be archived.
618 my $cannot_archive = $param{days_until}?-1:0;
619 # read the status information
620 my $status = $param{status};
621 if (not exists $param{status} or not defined $status) {
622 $status = read_bug(bug=>$param{bug});
623 if (not defined $status) {
624 print STDERR "Cannot archive $param{bug} because it does not exist\n" if $DEBUG;
628 # Bugs can be archived if they are
630 if (not defined $status->{done} or not length $status->{done}) {
631 print STDERR "Cannot archive $param{bug} because it is not done\n" if $DEBUG;
632 return $cannot_archive
634 # If we just are checking if the bug can be archived, we'll not even bother
635 # checking the versioning information if the bug has been -done for less than 28 days.
636 my $log_file = getbugcomponent($param{bug},'log');
637 if (not defined $log_file) {
638 print STDERR "Cannot archive $param{bug} because the log doesn't exist\n" if $DEBUG;
639 return $cannot_archive;
641 my $max_log_age = max(map {$config{remove_age} - -M $_}
642 $log_file, map {my $log = getbugcomponent($_,'log');
643 defined $log ? ($log) : ();
645 split / /, $status->{mergedwith}
647 if (not $param{days_until} and not $param{ignore_time}
650 print STDERR "Cannot archive $param{bug} because of time\n" if $DEBUG;
651 return $cannot_archive;
653 # At this point, we have to get the versioning information for this bug.
654 # We examine the set of distribution tags. If a bug has no distribution
655 # tags set, we assume a default set, otherwise we use the tags the bug
658 # In cases where we are assuming a default set, if the severity
659 # is strong, we use the strong severity default; otherwise, we
660 # use the normal default.
662 # There must be fixed_versions for us to look at the versioning
664 my $min_fixed_time = time;
665 my $min_archive_days = 0;
666 if (@{$status->{fixed_versions}}) {
668 @dist_tags{@{$config{removal_distribution_tags}}} =
669 (1) x @{$config{removal_distribution_tags}};
671 for my $tag (split ' ', ($status->{tags}||'')) {
672 next unless exists $config{distribution_aliases}{$tag};
673 next unless $dist_tags{$config{distribution_aliases}{$tag}};
674 $dists{$config{distribution_aliases}{$tag}} = 1;
676 if (not keys %dists) {
677 if (isstrongseverity($status->{severity})) {
678 @dists{@{$config{removal_strong_severity_default_distribution_tags}}} =
679 (1) x @{$config{removal_strong_severity_default_distribution_tags}};
682 @dists{@{$config{removal_default_distribution_tags}}} =
683 (1) x @{$config{removal_default_distribution_tags}};
687 my @sourceversions = get_versions(package => $status->{package},
688 dist => [keys %dists],
691 @source_versions{@sourceversions} = (1) x @sourceversions;
692 # If the bug has not been fixed in the versions actually
693 # distributed, then it cannot be archived.
694 if ('found' eq max_buggy(bug => $param{bug},
695 sourceversions => [keys %source_versions],
696 found => $status->{found_versions},
697 fixed => $status->{fixed_versions},
698 version_cache => $version_cache,
699 package => $status->{package},
701 print STDERR "Cannot archive $param{bug} because it's found\n" if $DEBUG;
702 return $cannot_archive;
704 # Since the bug has at least been fixed in the architectures
705 # that matters, we check to see how long it has been fixed.
707 # If $param{ignore_time}, then we should ignore time.
708 if ($param{ignore_time}) {
709 return $param{days_until}?0:1;
712 # To do this, we order the times from most recent to oldest;
713 # when we come to the first found version, we stop.
714 # If we run out of versions, we only report the time of the
716 my %time_versions = get_versions(package => $status->{package},
717 dist => [keys %dists],
721 for my $version (sort {$time_versions{$b} <=> $time_versions{$a}} keys %time_versions) {
722 my $buggy = buggy(bug => $param{bug},
724 found => $status->{found_versions},
725 fixed => $status->{fixed_versions},
726 version_cache => $version_cache,
727 package => $status->{package},
729 last if $buggy eq 'found';
730 $min_fixed_time = min($time_versions{$version},$min_fixed_time);
732 $min_archive_days = max($min_archive_days,ceil($config{remove_age} - (time - $min_fixed_time)/(60*60*24)));
734 # If $param{ignore_time}, then we should ignore time.
735 if ($param{ignore_time}) {
736 return $param{days_until}?0:1;
738 # 6. at least 28 days have passed since the last action has occured or the bug was closed
739 my $age = ceil($max_log_age);
740 if ($age > 0 or $min_archive_days > 0) {
741 print STDERR "Cannot archive $param{bug} because not enough days have passed\n" if $DEBUG;
742 return $param{days_until}?max($age,$min_archive_days):0;
745 return $param{days_until}?0:1;
750 =head2 get_bug_status
752 my $status = get_bug_status(bug => $nnn);
754 my $status = get_bug_status($bug_num)
760 =item bug -- scalar bug number
762 =item status -- optional hashref of bug status as returned by readbug
763 (can be passed to avoid rereading the bug information)
765 =item bug_index -- optional tied index of bug status infomration;
766 currently not correctly implemented.
768 =item version -- optional version(s) to check package status at
770 =item dist -- optional distribution(s) to check package status at
772 =item arch -- optional architecture(s) to check package status at
774 =item bugusertags -- optional hashref of bugusertags
776 =item sourceversion -- optional arrayref of source/version; overrides
777 dist, arch, and version. [The entries in this array must be in the
778 "source/version" format.] Eventually this can be used to for caching.
780 =item indicatesource -- if true, indicate which source packages this
781 bug could belong to. Defaults to false. [Note that eventually we will
782 properly allow bugs that only affect a source package, and this will
787 Note: Currently the version information is cached; this needs to be
788 changed before using this function in long lived programs.
796 my %param = validate_with(params => \@_,
797 spec => {bug => {type => SCALAR,
800 status => {type => HASHREF,
803 bug_index => {type => OBJECT,
806 version => {type => SCALAR|ARRAYREF,
809 dist => {type => SCALAR|ARRAYREF,
812 arch => {type => SCALAR|ARRAYREF,
815 bugusertags => {type => HASHREF,
818 sourceversions => {type => ARRAYREF,
821 indicatesource => {type => BOOLEAN,
828 if (defined $param{bug_index} and
829 exists $param{bug_index}{$param{bug}}) {
830 %status = %{ $param{bug_index}{$param{bug}} };
831 $status{pending} = $status{ status };
832 $status{id} = $param{bug};
835 if (defined $param{status}) {
836 %status = %{$param{status}};
839 my $location = getbuglocation($param{bug}, 'summary');
840 return {} if not defined $location or not length $location;
841 %status = %{ readbug( $param{bug}, $location ) };
843 $status{id} = $param{bug};
845 if (defined $param{bugusertags}{$param{bug}}) {
846 $status{keywords} = "" unless defined $status{keywords};
847 $status{keywords} .= " " unless $status{keywords} eq "";
848 $status{keywords} .= join(" ", @{$param{bugusertags}{$param{bug}}});
850 $status{tags} = $status{keywords};
851 my %tags = map { $_ => 1 } split ' ', $status{tags};
853 $status{"package"} =~ s/\s*$//;
854 if ($param{indicatesource} and $status{package} ne '') {
855 $status{source} = join(', ',binarytosource($status{package}));
858 $status{source} = 'unknown';
860 $status{"package"} = 'unknown' if ($status{"package"} eq '');
861 $status{"severity"} = 'normal' if ($status{"severity"} eq '');
863 $status{"pending"} = 'pending';
864 $status{"pending"} = 'forwarded' if (length($status{"forwarded"}));
865 $status{"pending"} = 'pending-fixed' if ($tags{pending});
866 $status{"pending"} = 'fixed' if ($tags{fixed});
869 my $presence = bug_presence(map{(exists $param{$_})?($_,$param{$_}):()}
870 qw(bug sourceversions arch dist version found fixed package)
872 if (defined $presence) {
873 if ($presence eq 'fixed') {
874 $status{pending} = 'done';
876 elsif ($presence eq 'absent') {
877 $status{pending} = 'absent';
885 my $precence = bug_presence(bug => nnn,
889 Returns 'found', 'absent', 'fixed' or undef based on whether the bug
890 is found, absent, fixed, or no information is available in the
891 distribution (dist) and/or architecture (arch) specified.
898 =item bug -- scalar bug number
900 =item status -- optional hashref of bug status as returned by readbug
901 (can be passed to avoid rereading the bug information)
903 =item bug_index -- optional tied index of bug status infomration;
904 currently not correctly implemented.
906 =item version -- optional version to check package status at
908 =item dist -- optional distribution to check package status at
910 =item arch -- optional architecture to check package status at
912 =item sourceversion -- optional arrayref of source/version; overrides
913 dist, arch, and version. [The entries in this array must be in the
914 "source/version" format.] Eventually this can be used to for caching.
921 my %param = validate_with(params => \@_,
922 spec => {bug => {type => SCALAR,
925 status => {type => HASHREF,
928 version => {type => SCALAR|ARRAYREF,
931 dist => {type => SCALAR|ARRAYREF,
934 arch => {type => SCALAR|ARRAYREF,
937 sourceversions => {type => ARRAYREF,
943 if (defined $param{status}) {
944 %status = %{$param{status}};
947 my $location = getbuglocation($param{bug}, 'summary');
948 return {} if not length $location;
949 %status = %{ readbug( $param{bug}, $location ) };
953 my $pseudo_desc = getpseudodesc();
954 if (not exists $param{sourceversions}) {
956 # pseudopackages do not have source versions by definition.
957 if (exists $pseudo_desc->{$status{package}}) {
960 elsif (defined $param{version}) {
961 foreach my $arch (make_list($param{arch})) {
962 for my $package (split /\s*,\s*/, $status{package}) {
963 my @temp = makesourceversions($package,
965 make_list($param{version})
967 @sourceversions{@temp} = (1) x @temp;
970 } elsif (defined $param{dist}) {
971 foreach my $arch (make_list($param{arch})) {
973 for my $package (split /\s*,\s*/, $status{package}) {
974 foreach my $dist (make_list($param{dist})) {
975 push @versions, getversions($package, $dist, $arch);
977 my @temp = makesourceversions($package,
981 @sourceversions{@temp} = (1) x @temp;
986 # TODO: This should probably be handled further out for efficiency and
987 # for more ease of distinguishing between pkg= and src= queries.
988 # DLA: src= queries should just pass arch=source, and they'll be happy.
989 @sourceversions = keys %sourceversions;
992 @sourceversions = @{$param{sourceversions}};
994 my $maxbuggy = 'undef';
995 if (@sourceversions) {
996 $maxbuggy = max_buggy(bug => $param{bug},
997 sourceversions => \@sourceversions,
998 found => $status{found_versions},
999 fixed => $status{fixed_versions},
1000 package => $status{package},
1001 version_cache => $version_cache,
1004 elsif (defined $param{dist} and
1005 not exists $pseudo_desc->{$status{package}}) {
1008 if (length($status{done}) and
1009 (not @sourceversions or not @{$status{fixed_versions}})) {
1024 =item bug -- scalar bug number
1026 =item sourceversion -- optional arrayref of source/version; overrides
1027 dist, arch, and version. [The entries in this array must be in the
1028 "source/version" format.] Eventually this can be used to for caching.
1032 Note: Currently the version information is cached; this needs to be
1033 changed before using this function in long lived programs.
1038 my %param = validate_with(params => \@_,
1039 spec => {bug => {type => SCALAR,
1042 sourceversions => {type => ARRAYREF,
1045 found => {type => ARRAYREF,
1048 fixed => {type => ARRAYREF,
1051 package => {type => SCALAR,
1053 version_cache => {type => HASHREF,
1058 # Resolve bugginess states (we might be looking at multiple
1059 # architectures, say). Found wins, then fixed, then absent.
1060 my $maxbuggy = 'absent';
1061 for my $package (split /\s*,\s*/, $param{package}) {
1062 for my $version (@{$param{sourceversions}}) {
1063 my $buggy = buggy(bug => $param{bug},
1064 version => $version,
1065 found => $param{found},
1066 fixed => $param{fixed},
1067 version_cache => $param{version_cache},
1068 package => $package,
1070 if ($buggy eq 'found') {
1072 } elsif ($buggy eq 'fixed') {
1073 $maxbuggy = 'fixed';
1090 Returns the output of Debbugs::Versions::buggy for a particular
1091 package, version and found/fixed set. Automatically turns found, fixed
1092 and version into source/version strings.
1094 Caching can be had by using the version_cache, but no attempt to check
1095 to see if the on disk information is more recent than the cache is
1096 made. [This will need to be fixed for long-lived processes.]
1101 my %param = validate_with(params => \@_,
1102 spec => {bug => {type => SCALAR,
1105 found => {type => ARRAYREF,
1108 fixed => {type => ARRAYREF,
1111 version_cache => {type => HASHREF,
1114 package => {type => SCALAR,
1116 version => {type => SCALAR,
1120 my @found = @{$param{found}};
1121 my @fixed = @{$param{fixed}};
1122 if (grep {$_ !~ m{/}} (@{$param{found}}, @{$param{fixed}})) {
1123 # We have non-source version versions
1124 @found = makesourceversions($param{package},undef,
1127 @fixed = makesourceversions($param{package},undef,
1131 if ($param{version} !~ m{/}) {
1132 my ($version) = makesourceversions($param{package},undef,
1135 $param{version} = $version if defined $version;
1137 # Figure out which source packages we need
1139 @sources{map {m{(.+)/}; $1} @found} = (1) x @found;
1140 @sources{map {m{(.+)/}; $1} @fixed} = (1) x @fixed;
1141 @sources{map {m{(.+)/}; $1} $param{version}} = 1 if
1142 $param{version} =~ m{/};
1144 if (not defined $param{version_cache} or
1145 not exists $param{version_cache}{join(',',sort keys %sources)}) {
1146 $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp);
1147 foreach my $source (keys %sources) {
1148 my $srchash = substr $source, 0, 1;
1149 my $version_fh = IO::File->new("$config{version_packages_dir}/$srchash/$source", 'r');
1150 if (not defined $version_fh) {
1151 # We only want to warn if it's a package which actually has a maintainer
1152 my $maints = getmaintainers();
1153 next if not exists $maints->{$source};
1154 warn "Bug $param{bug}: unable to open $config{version_packages_dir}/$srchash/$source: $!";
1157 $version->load($version_fh);
1159 if (defined $param{version_cache}) {
1160 $param{version_cache}{join(',',sort keys %sources)} = $version;
1164 $version = $param{version_cache}{join(',',sort keys %sources)};
1166 return $version->buggy($param{version},\@found,\@fixed);
1169 sub isstrongseverity {
1170 my $severity = shift;
1171 $severity = $config{default_severity} if
1172 not defined $severity or $severity eq '';
1173 return grep { $_ eq $severity } @{$config{strong_severities}};
1177 =head1 PRIVATE FUNCTIONS
1181 sub update_realtime {
1182 my ($file, %bugs) = @_;
1184 # update realtime index.db
1186 return () unless keys %bugs;
1187 my $idx_old = IO::File->new($file,'r')
1188 or die "Couldn't open ${file}: $!";
1189 my $idx_new = IO::File->new($file.'.new','w')
1190 or die "Couldn't open ${file}.new: $!";
1192 my $min_bug = min(keys %bugs);
1196 while($line = <$idx_old>) {
1197 @line = split /\s/, $line;
1198 # Two cases; replacing existing line or adding new line
1199 if (exists $bugs{$line[1]}) {
1200 my $new = $bugs{$line[1]};
1201 delete $bugs{$line[1]};
1202 $min_bug = min(keys %bugs);
1203 if ($new eq "NOCHANGE") {
1204 print {$idx_new} $line;
1205 $changed_bugs{$line[1]} = $line;
1206 } elsif ($new eq "REMOVE") {
1207 $changed_bugs{$line[1]} = $line;
1209 print {$idx_new} $new;
1210 $changed_bugs{$line[1]} = $line;
1214 while ($line[1] > $min_bug) {
1215 print {$idx_new} $bugs{$min_bug};
1216 delete $bugs{$min_bug};
1217 last unless keys %bugs;
1218 $min_bug = min(keys %bugs);
1220 print {$idx_new} $line;
1222 last unless keys %bugs;
1224 print {$idx_new} map {$bugs{$_}} sort keys %bugs;
1226 print {$idx_new} <$idx_old>;
1231 rename("$file.new", $file);
1233 return %changed_bugs;
1236 sub bughook_archive {
1238 &filelock("debbugs.trace.lock");
1239 &appendfile("debbugs.trace","archive ".join(',',@refs)."\n");
1240 my %bugs = update_realtime("$config{spool_dir}/index.db.realtime",
1241 map{($_,'REMOVE')} @refs);
1242 update_realtime("$config{spool_dir}/index.archive.realtime",
1248 my ( $type, %bugs_temp ) = @_;
1249 &filelock("debbugs.trace.lock");
1252 for my $bug (keys %bugs_temp) {
1253 my $data = $bugs_temp{$bug};
1254 &appendfile("debbugs.trace","$type $bug\n",makestatus($data, 1));
1256 my $whendone = "open";
1257 my $severity = $config{default_severity};
1258 (my $pkglist = $data->{package}) =~ s/[,\s]+/,/g;
1259 $pkglist =~ s/^,+//;
1260 $pkglist =~ s/,+$//;
1261 $whendone = "forwarded" if defined $data->{forwarded} and length $data->{forwarded};
1262 $whendone = "done" if defined $data->{done} and length $data->{done};
1263 $severity = $data->{severity} if length $data->{severity};
1265 my $k = sprintf "%s %d %d %s [%s] %s %s\n",
1266 $pkglist, $bug, $data->{date}, $whendone,
1267 $data->{originator}, $severity, $data->{keywords};
1270 update_realtime("$config{spool_dir}/index.db.realtime", %bugs);