1 # Copyright © 1998 Richard Braakman
2 # Copyright © 1999 Darren Benham
3 # Copyright © 2000 Sean 'Shaleh' Perry
4 # Copyright © 2004 Frank Lichtenheld
5 # Copyright © 2006 Russ Allbery
6 # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
7 # Copyright © 2008-2009, 2012-2014 Guillem Jover <guillem@debian.org>
9 # This program is free software; you may redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
26 Dpkg::Deps::KnownFacts - list of installed real and virtual packages
30 This class represents a list of installed packages and a list of virtual
31 packages provided (by the set of installed packages).
35 package Dpkg
::Deps
::KnownFacts
2.00;
46 =item $facts = Dpkg::Deps::KnownFacts->new();
54 my $class = ref($this) || $this;
64 =item $facts->add_installed_package($package, $version, $arch, $multiarch)
66 Records that the given version of the package is installed. If
67 $version/$arch is undefined we know that the package is installed but we
68 don't know which version/architecture it is. $multiarch is the Multi-Arch
69 field of the package. If $multiarch is undef, it will be equivalent to
72 Note that $multiarch is only used if $arch is provided.
76 sub add_installed_package
{
77 my ($self, $pkg, $ver, $arch, $multiarch) = @_;
81 architecture
=> $arch,
82 multiarch
=> $multiarch // 'no',
85 $self->{pkg
}{"$pkg:$arch"} = $p if defined $arch;
86 push @
{$self->{pkg
}{$pkg}}, $p;
89 =item $facts->add_provided_package($virtual, $relation, $version, $by)
91 Records that the "$by" package provides the $virtual package. $relation
92 and $version correspond to the associated relation given in the Provides
97 sub add_provided_package
{
98 my ($self, $pkg, $rel, $ver, $by) = @_;
106 $self->{virtualpkg
}{$pkg} //= [];
107 push @
{$self->{virtualpkg
}{$pkg}}, $v;
111 ## The functions below are private to Dpkg::Deps::KnownFacts.
115 my ($self, $dep, $lackinfos) = @_;
116 my ($pkg, $archqual) = ($dep->{package}, $dep->{archqual
});
118 return if not exists $self->{pkg
}{$pkg};
120 my $host_arch = $dep->{host_arch
} // Dpkg
::Arch
::get_host_arch
();
121 my $build_arch = $dep->{build_arch
} // Dpkg
::Arch
::get_build_arch
();
123 foreach my $p (@
{$self->{pkg
}{$pkg}}) {
124 my $a = $p->{architecture
};
125 my $ma = $p->{multiarch
};
127 if (not defined $a) {
131 if (not defined $archqual) {
132 return $p if $ma eq 'foreign';
133 return $p if $a eq $host_arch or $a eq 'all';
134 } elsif ($archqual eq 'any') {
135 return $p if $ma eq 'allowed';
136 } elsif ($archqual eq 'native') {
137 return if $ma eq 'foreign';
138 return $p if $a eq $build_arch or $a eq 'all';
140 return $p if $a eq $archqual;
146 sub _find_virtual_packages
{
147 my ($self, $pkg) = @_;
149 return () if not exists $self->{virtualpkg
}{$pkg};
150 return @
{$self->{virtualpkg
}{$pkg}};
153 =item $facts->evaluate_simple_dep()
155 This method is private and should not be used except from within L<Dpkg::Deps>.
159 sub evaluate_simple_dep
{
160 my ($self, $dep) = @_;
161 my ($lackinfos, $pkg) = (0, $dep->{package});
163 my $p = $self->_find_package($dep, \
$lackinfos);
165 if (defined $dep->{relation
}) {
166 if (defined $p->{version
}) {
167 return 1 if version_compare_relation
($p->{version
},
177 foreach my $virtpkg ($self->_find_virtual_packages($pkg)) {
178 next if defined $virtpkg->{relation
} and
179 $virtpkg->{relation
} ne REL_EQ
;
181 if (defined $dep->{relation
}) {
182 next if not defined $virtpkg->{version
};
183 return 1 if version_compare_relation
($virtpkg->{version
},
190 return if $lackinfos;
198 =head2 Version 2.00 (dpkg 1.20.0)
200 Remove method: $facts->check_package().
202 =head2 Version 1.01 (dpkg 1.16.1)
204 New option: $facts->add_installed_package() now accepts 2
205 supplementary parameters ($arch and $multiarch).
207 Deprecated method: $facts->check_package() is obsolete,
208 it should not have been part of the public API.
210 =head2 Version 1.00 (dpkg 1.15.6)
212 Mark the module as public.