| 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> | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # This program is free software; you can 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. | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # This program 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. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 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/>. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =encoding utf8 | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Dpkg::Deps::KnownFacts - list of installed real and virtual packages | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | This class represents a list of installed packages and a list of virtual | ||||||||||||||||||||||||||||
| 31 | packages provided (by the set of installed packages). | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | package Dpkg::Deps::KnownFacts 2.00; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | ▶ | use Dpkg::Version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item $facts = Dpkg::Deps::KnownFacts->new(); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Creates a new object. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||
| 54 | 1 | my $self = { | |||||||||||||||||||||||||||
| 55 | pkg => {}, | ||||||||||||||||||||||||||||
| 56 | virtualpkg => {}, | ||||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 60 | 1 | return $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item $facts->add_installed_package($package, $version, $arch, $multiarch) | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Records that the given version of the package is installed. If | ||||||||||||||||||||||||||||
| 66 | $version/$arch is undefined we know that the package is installed but we | ||||||||||||||||||||||||||||
| 67 | don't know which version/architecture it is. $multiarch is the Multi-Arch | ||||||||||||||||||||||||||||
| 68 | field of the package. If $multiarch is undef, it will be equivalent to | ||||||||||||||||||||||||||||
| 69 | "Multi-Arch: no". | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Note that $multiarch is only used if $arch is provided. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 9 | ▶ | sub add_installed_package { | ||||||||||||||||||||||||||
|
Subroutine
add_installed_package: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 9 | my ($self, $pkg, $ver, $arch, $multiarch) = @_; | |||||||||||||||||||||||||||
| 77 | 9 | ▶ | my $p = { | ||||||||||||||||||||||||||
|
Condition50%1/2
$multiarch // "no"
MC/DC0%0/1
$multiarch // "no"
$multiarch
Truth table50%1/2
A
A= $multiarch
| |||||||||||||||||||||||||||||
| 78 | package => $pkg, | ||||||||||||||||||||||||||||
| 79 | version => $ver, | ||||||||||||||||||||||||||||
| 80 | architecture => $arch, | ||||||||||||||||||||||||||||
| 81 | multiarch => $multiarch // 'no', | ||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 9 | ▶ | $self->{pkg}{"$pkg:$arch"} = $p if defined $arch; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 9 | push @{$self->{pkg}{$pkg}}, $p; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item $facts->add_provided_package($virtual, $relation, $version, $by) | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Records that the "$by" package provides the $virtual package. $relation | ||||||||||||||||||||||||||||
| 91 | and $version correspond to the associated relation given in the Provides | ||||||||||||||||||||||||||||
| 92 | field (if present). | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | ▶ | sub add_provided_package { | ||||||||||||||||||||||||||
|
Subroutine
add_provided_package: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 3 | my ($self, $pkg, $rel, $ver, $by) = @_; | |||||||||||||||||||||||||||
| 98 | 3 | my $v = { | |||||||||||||||||||||||||||
| 99 | package => $pkg, | ||||||||||||||||||||||||||||
| 100 | relation => $rel, | ||||||||||||||||||||||||||||
| 101 | version => $ver, | ||||||||||||||||||||||||||||
| 102 | provider => $by, | ||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | $self->{virtualpkg}{$pkg} //= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"virtualpkg"}{$pkg} //= []
MC/DC0%0/1
$self->{"virtualpkg"}{$pkg} //= []
$self->{"virtualpkg"}{$pkg}
Truth table50%1/2
A
A= $self->{"virtualpkg"}{$pkg}
| |||||||||||||||||||||||||||||
| 106 | 3 | push @{$self->{virtualpkg}{$pkg}}, $v; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | ## Private functions. | ||||||||||||||||||||||||||||
| 110 | # | ||||||||||||||||||||||||||||
| 111 | # Note: The functions below are private to Dpkg::Deps::KnownFacts. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 56 | ▶ | sub _find_package { | ||||||||||||||||||||||||||
|
Subroutine
_find_package: called CC=17 SCAR=31.4
| |||||||||||||||||||||||||||||
| 114 | 56 | my ($self, $dep, $lackinfos) = @_; | |||||||||||||||||||||||||||
| 115 | 56 | my ($pkg, $archqual) = ($dep->{package}, $dep->{archqual}); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 56 | ▶ | return if not exists $self->{pkg}{$pkg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 11 | ▶ | my $host_arch = $dep->{host_arch} // Dpkg::Arch::get_host_arch(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$dep->{"host_arch"} // Dpkg::Arch::get_host_arch()
MC/DC0%0/2
$dep->{"host_arch"} // Dpkg::Arch::get_host_arch()
$dep->{"host_arch"}
Dpkg::Arch::get_host_arch()
Truth table33%1/3
A // B
A= $dep->{"host_arch"}B= Dpkg::Arch::get_host_arch()
| |||||||||||||||||||||||||||||
| 120 | 11 | ▶ | my $build_arch = $dep->{build_arch} // Dpkg::Arch::get_build_arch(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$dep->{"build_arch"} // Dpkg::Arch::get_build_arch()
MC/DC0%0/2
$dep->{"build_arch"} // Dpkg::Arch::get_build_arch()
$dep->{"build_arch"}
Dpkg::Arch::get_build_arch()
Truth table33%1/3
A // B
A= $dep->{"build_arch"}B= Dpkg::Arch::get_build_arch()
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 11 | foreach my $p (@{$self->{pkg}{$pkg}}) { | |||||||||||||||||||||||||||
| 123 | 11 | my $a = $p->{architecture}; | |||||||||||||||||||||||||||
| 124 | 11 | my $ma = $p->{multiarch}; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 11 | ▶ | if (not defined $a) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | $$lackinfos = 1; | |||||||||||||||||||||||||||
| 128 | 0 | next; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 11 | ▶ | if (not defined $archqual) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 131 | 8 | ▶ | return $p if $ma eq 'foreign'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | return $p if $a eq $host_arch or $a eq 'all'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$a eq $host_arch or $a eq "all"
MC/DC100%2/2
$a eq $host_arch or $a eq "all"
$a eq $host_arch
$a eq "all"
Truth table100%3/3
A or B
A= $a eq $host_archB= $a eq "all"
| |||||||||||||||||||||||||||||
| 133 | } elsif ($archqual eq 'any') { | ||||||||||||||||||||||||||||
| 134 | 1 | ▶ | return $p if $ma eq 'allowed'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | } elsif ($archqual eq 'native') { | ||||||||||||||||||||||||||||
| 136 | 2 | ▶ | return if $ma eq 'foreign'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | return $p if $a eq $build_arch or $a eq 'all'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$a eq $build_arch or $a eq "all"
MC/DC0%0/2
$a eq $build_arch or $a eq "all"
$a eq $build_arch
$a eq "all"
Truth table33%1/3
A or B
A= $a eq $build_archB= $a eq "all"
| |||||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return $p if $a eq $archqual; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 2 | return; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 48 | ▶ | sub _find_virtual_packages { | ||||||||||||||||||||||||||
|
Subroutine
_find_virtual_packages: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 146 | 48 | my ($self, $pkg) = @_; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 48 | ▶ | return () if not exists $self->{virtualpkg}{$pkg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 6 | return @{$self->{virtualpkg}{$pkg}}; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =item $facts->evaluate_simple_dep() | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | This method is private and should not be used except from within L<Dpkg::Deps>. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 56 | ▶ | sub evaluate_simple_dep { | ||||||||||||||||||||||||||
|
Subroutine
evaluate_simple_dep: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 56 | my ($self, $dep) = @_; | |||||||||||||||||||||||||||
| 160 | 56 | my ($lackinfos, $pkg) = (0, $dep->{package}); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 56 | my $p = $self->_find_package($dep, \$lackinfos); | |||||||||||||||||||||||||||
| 163 | 56 | ▶ | if ($p) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 8 | ▶ | if (defined $dep->{relation}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 1 | ▶ | if (defined $p->{version}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | return 1 if version_compare_relation($p->{version}, | ||||||||||||||||||||||||||||
| 167 | $dep->{relation}, | ||||||||||||||||||||||||||||
| 168 | 1 | ▶ | $dep->{version}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | } else { | ||||||||||||||||||||||||||||
| 170 | 0 | $lackinfos = 1; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||
| 173 | 7 | return 1; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 48 | foreach my $virtpkg ($self->_find_virtual_packages($pkg)) { | |||||||||||||||||||||||||||
| 177 | next if defined $virtpkg->{relation} and | ||||||||||||||||||||||||||||
| 178 | 6 | ▶ | $virtpkg->{relation} ne REL_EQ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $virtpkg->{"relation"} and $virtpkg->{"relation"} ne "="
MC/DC100%2/2
defined $virtpkg->{"relation"} and $virtpkg->{"relation"} ne "="
defined $virtpkg->{"relation"}
$virtpkg->{"relation"} ne "="
Truth table100%3/3
A and B
A= defined $virtpkg->{"relation"}B= $virtpkg->{"relation"} ne "="
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 5 | ▶ | if (defined $dep->{relation}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 3 | ▶ | next if not defined $virtpkg->{version}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | return 1 if version_compare_relation($virtpkg->{version}, | ||||||||||||||||||||||||||||
| 183 | $dep->{relation}, | ||||||||||||||||||||||||||||
| 184 | 2 | ▶ | $dep->{version}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||
| 186 | 2 | return 1; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | 45 | ▶ | return if $lackinfos; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 45 | return 0; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =back | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head2 Version 2.00 (dpkg 1.20.0) | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | Remove method: $facts->check_package(). | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head2 Version 1.01 (dpkg 1.16.1) | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | New option: $facts->add_installed_package() now accepts 2 | ||||||||||||||||||||||||||||
| 204 | supplementary parameters ($arch and $multiarch). | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Deprecated method: $facts->check_package() is obsolete, | ||||||||||||||||||||||||||||
| 207 | it should not have been part of the public API. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Mark the module as public. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 4 | 1; | |||||||||||||||||||||||||||