1 package Debbugs::Packages;
5 # TODO: move config handling to a separate module
6 my $config_path = '/etc/debbugs';
7 require "$config_path/config";
10 use vars qw($VERSION @ISA @EXPORT);
16 @EXPORT = qw(getpkgsrc getpkgcomponent getsrcpkgs
17 binarytosource sourcetobinary);
20 use Fcntl qw(O_RDONLY);
21 use MLDBM qw(DB_File);
23 $MLDBM::RemoveTaint = 1;
27 Debbugs::Packages - debbugs binary/source package handling
31 The Debbugs::Packages module provides support functions to map binary
32 packages to their corresponding source packages and vice versa. (This makes
33 sense for software distributions, where developers may work on a single
34 source package which produces several binary packages for use by users; it
35 may not make sense in other contexts.)
43 Returns a reference to a hash of binary package names to their corresponding
51 return $_pkgsrc if $_pkgsrc;
52 return {} unless defined $Debbugs::Packages::gPackageSource;
56 open(MM,"$Debbugs::Packages::gPackageSource")
57 or &quitcgi("open $Debbugs::Packages::gPackageSource: $!");
59 next unless m/^(\S+)\s+(\S+)\s+(\S.*\S)\s*$/;
60 my ($bin,$cmp,$src)=($1,$2,$3);
63 $pkgcomponent{$bin}= $cmp;
67 $_pkgcomponent = \%pkgcomponent;
73 Returns a reference to a hash of binary package names to the component of
74 the archive containing those binary packages (e.g. "main", "contrib",
80 return $_pkgcomponent if $_pkgcomponent;
82 return $_pkgcomponent;
87 Returns a list of the binary packages produced by a given source package.
94 my %pkgsrc = %{getpkgsrc()};
96 foreach ( keys %pkgsrc ) {
97 push @pkgs, $_ if $pkgsrc{$_} eq $src;
104 Returns a reference to the source package name and version pair
105 corresponding to a given binary package name, version, and architecture. If
106 undef is passed as the architecture, returns a list of references to all
107 possible pairs of source package names and versions for all architectures,
108 with any duplicates removed.
114 my ($binname, $binver, $binarch) = @_;
116 # TODO: This gets hit a lot, especially from buggyversion() - probably
117 # need an extra cache for speed here.
119 if (tied %_binarytosource or
120 tie %_binarytosource, 'MLDBM',
121 $Debbugs::Packages::gBinarySourceMap, O_RDONLY) {
122 # avoid autovivification
123 if (exists $_binarytosource{$binname} and
124 exists $_binarytosource{$binname}{$binver}) {
125 if (defined $binarch) {
126 my $src = $_binarytosource{$binname}{$binver}{$binarch};
127 return () unless defined $src; # not on this arch
128 # Copy the data to avoid tiedness problems.
131 # Get (srcname, srcver) pairs for all architectures and
132 # remove any duplicates. This involves some slightly tricky
133 # multidimensional hashing; sorry. Fortunately there'll
134 # usually only be one pair returned.
136 for my $ar (keys %{$_binarytosource{$binname}{$binver}}) {
137 my $src = $_binarytosource{$binname}{$binver}{$ar};
138 next unless defined $src;
139 $uniq{$src->[0]}{$src->[1]} = 1;
142 for my $sn (sort keys %uniq) {
143 push @uniq, [$sn, $_] for sort keys %{$uniq{$sn}};
150 # No $gBinarySourceMap, or it didn't have an entry for this name and
151 # version. Try $gPackageSource (unversioned) instead.
152 my $pkgsrc = getpkgsrc();
153 if (exists $pkgsrc->{$binname}) {
154 return [$pkgsrc->{$binname}, $binver];
162 Returns a list of references to triplets of binary package names, versions,
163 and architectures corresponding to a given source package name and version.
164 If the given source package name and version cannot be found in the database
165 but the source package name is in the unversioned package-to-source map
166 file, then a reference to a binary package name and version pair will be
167 returned, without the architecture.
173 my ($srcname, $srcver) = @_;
175 if (tied %_sourcetobinary or
176 tie %_sourcetobinary, 'MLDBM',
177 $Debbugs::Packages::gSourceBinaryMap, O_RDONLY) {
178 # avoid autovivification
179 if (exists $_sourcetobinary{$srcname} and
180 exists $_sourcetobinary{$srcname}{$srcver}) {
181 my $bin = $_sourcetobinary{$srcname}{$srcver};
182 return () unless defined $bin;
183 # Copy the data to avoid tiedness problems.
188 # No $gSourceBinaryMap, or it didn't have an entry for this name and
189 # version. Try $gPackageSource (unversioned) instead.
190 my @srcpkgs = getsrcpkgs($srcname);
191 return map [$_, $srcver], @srcpkgs;