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