]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
bac2e715 | 3 | // $Id: pkgcache.cc,v 1.37 2003/02/10 01:40:58 doogie Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Package Cache - Accessor code for the cache | |
7 | ||
094a497d | 8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of |
578bfd0a AL |
9 | this format. Also be sure to keep that file up-to-date!! |
10 | ||
1e3f4083 | 11 | This is the general utility functions for cache management. They provide |
578bfd0a AL |
12 | a complete set of accessor functions for the cache. The cacheiterators |
13 | header contains the STL-like iterators that can be used to easially | |
14 | navigate the cache as well as seemlessly dereference the mmap'd | |
15 | indexes. Use these always. | |
16 | ||
17 | The main class provides for ways to get package indexes and some | |
18 | general lookup functions to start the iterators. | |
19 | ||
20 | ##################################################################### */ | |
21 | /*}}}*/ | |
22 | // Include Files /*{{{*/ | |
ea542140 DK |
23 | #include<config.h> |
24 | ||
094a497d | 25 | #include <apt-pkg/pkgcache.h> |
af29ffb4 | 26 | #include <apt-pkg/policy.h> |
094a497d AL |
27 | #include <apt-pkg/version.h> |
28 | #include <apt-pkg/error.h> | |
231fea14 | 29 | #include <apt-pkg/strutl.h> |
b2e465d6 | 30 | #include <apt-pkg/configuration.h> |
45df0ad2 | 31 | #include <apt-pkg/aptconfiguration.h> |
453b82a3 | 32 | #include <apt-pkg/mmap.h> |
5c0d3668 | 33 | #include <apt-pkg/macros.h> |
578bfd0a | 34 | |
453b82a3 DK |
35 | #include <stddef.h> |
36 | #include <string.h> | |
7f8c0eed DK |
37 | #include <sstream> |
38 | #include <algorithm> | |
453b82a3 | 39 | #include <vector> |
578bfd0a AL |
40 | #include <string> |
41 | #include <sys/stat.h> | |
25c7a09d | 42 | #include <zlib.h> |
ea542140 DK |
43 | |
44 | #include <apti18n.h> | |
578bfd0a AL |
45 | /*}}}*/ |
46 | ||
851a45a8 | 47 | using std::string; |
eff0c22e | 48 | using APT::StringView; |
851a45a8 | 49 | |
012b102a | 50 | |
578bfd0a AL |
51 | // Cache::Header::Header - Constructor /*{{{*/ |
52 | // --------------------------------------------------------------------- | |
53 | /* Simply initialize the header */ | |
54 | pkgCache::Header::Header() | |
55 | { | |
dfe66c72 DK |
56 | #define APT_HEADER_SET(X,Y) X = Y; static_assert(std::numeric_limits<decltype(X)>::max() > Y, "Size violation detected in pkgCache::Header") |
57 | APT_HEADER_SET(Signature, 0x98FE76DC); | |
58 | ||
578bfd0a AL |
59 | /* Whenever the structures change the major version should be bumped, |
60 | whenever the generator changes the minor version should be bumped. */ | |
dfe66c72 | 61 | APT_HEADER_SET(MajorVersion, 10); |
60d523e2 | 62 | APT_HEADER_SET(MinorVersion, 4); |
dfe66c72 DK |
63 | APT_HEADER_SET(Dirty, false); |
64 | ||
65 | APT_HEADER_SET(HeaderSz, sizeof(pkgCache::Header)); | |
66 | APT_HEADER_SET(GroupSz, sizeof(pkgCache::Group)); | |
67 | APT_HEADER_SET(PackageSz, sizeof(pkgCache::Package)); | |
68 | APT_HEADER_SET(ReleaseFileSz, sizeof(pkgCache::ReleaseFile)); | |
69 | APT_HEADER_SET(PackageFileSz, sizeof(pkgCache::PackageFile)); | |
70 | APT_HEADER_SET(VersionSz, sizeof(pkgCache::Version)); | |
71 | APT_HEADER_SET(DescriptionSz, sizeof(pkgCache::Description)); | |
72 | APT_HEADER_SET(DependencySz, sizeof(pkgCache::Dependency)); | |
73 | APT_HEADER_SET(DependencyDataSz, sizeof(pkgCache::DependencyData)); | |
74 | APT_HEADER_SET(ProvidesSz, sizeof(pkgCache::Provides)); | |
75 | APT_HEADER_SET(VerFileSz, sizeof(pkgCache::VerFile)); | |
76 | APT_HEADER_SET(DescFileSz, sizeof(pkgCache::DescFile)); | |
77 | #undef APT_HEADER_SET | |
78 | ||
52c41485 | 79 | GroupCount = 0; |
578bfd0a AL |
80 | PackageCount = 0; |
81 | VersionCount = 0; | |
a52f938b | 82 | DescriptionCount = 0; |
578bfd0a | 83 | DependsCount = 0; |
71c9e95b | 84 | DependsDataCount = 0; |
b07aeb1a | 85 | ReleaseFileCount = 0; |
578bfd0a | 86 | PackageFileCount = 0; |
a7e66b17 | 87 | VerFileCount = 0; |
a52f938b | 88 | DescFileCount = 0; |
a7e66b17 | 89 | ProvidesCount = 0; |
ad00ae81 | 90 | MaxVerFileSize = 0; |
a52f938b | 91 | MaxDescFileSize = 0; |
dfe66c72 | 92 | |
578bfd0a | 93 | FileList = 0; |
b07aeb1a | 94 | RlsFileList = 0; |
b2e465d6 AL |
95 | VerSysName = 0; |
96 | Architecture = 0; | |
32ab4bd0 | 97 | SetArchitectures(0); |
3b4cbca2 | 98 | SetHashTableSize(_config->FindI("APT::Cache-HashTableSize", 50503)); |
578bfd0a | 99 | memset(Pools,0,sizeof(Pools)); |
0688ccd8 JAK |
100 | |
101 | CacheFileSize = 0; | |
578bfd0a AL |
102 | } |
103 | /*}}}*/ | |
104 | // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/ | |
105 | // --------------------------------------------------------------------- | |
106 | /* */ | |
107 | bool pkgCache::Header::CheckSizes(Header &Against) const | |
108 | { | |
109 | if (HeaderSz == Against.HeaderSz && | |
52c41485 | 110 | GroupSz == Against.GroupSz && |
578bfd0a | 111 | PackageSz == Against.PackageSz && |
b07aeb1a | 112 | ReleaseFileSz == Against.ReleaseFileSz && |
578bfd0a AL |
113 | PackageFileSz == Against.PackageFileSz && |
114 | VersionSz == Against.VersionSz && | |
a52f938b | 115 | DescriptionSz == Against.DescriptionSz && |
dcb79bae | 116 | DependencySz == Against.DependencySz && |
71c9e95b | 117 | DependencyDataSz == Against.DependencyDataSz && |
dcb79bae | 118 | VerFileSz == Against.VerFileSz && |
a52f938b | 119 | DescFileSz == Against.DescFileSz && |
578bfd0a AL |
120 | ProvidesSz == Against.ProvidesSz) |
121 | return true; | |
122 | return false; | |
123 | } | |
124 | /*}}}*/ | |
125 | ||
126 | // Cache::pkgCache - Constructor /*{{{*/ | |
127 | // --------------------------------------------------------------------- | |
128 | /* */ | |
32ab4bd0 | 129 | APT_IGNORE_DEPRECATED_PUSH |
6c55f07a | 130 | pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), d(NULL) |
578bfd0a | 131 | { |
4cbf323f MV |
132 | // call getArchitectures() with cached=false to ensure that the |
133 | // architectures cache is re-evaulated. this is needed in cases | |
134 | // when the APT::Architecture field changes between two cache creations | |
135 | MultiArchEnabled = APT::Configuration::getArchitectures(false).size() > 1; | |
b2e465d6 AL |
136 | if (DoMap == true) |
137 | ReMap(); | |
578bfd0a | 138 | } |
32ab4bd0 | 139 | APT_IGNORE_DEPRECATED_POP |
578bfd0a AL |
140 | /*}}}*/ |
141 | // Cache::ReMap - Reopen the cache file /*{{{*/ | |
142 | // --------------------------------------------------------------------- | |
143 | /* If the file is already closed then this will open it open it. */ | |
a9fe5928 | 144 | bool pkgCache::ReMap(bool const &Errorchecks) |
578bfd0a AL |
145 | { |
146 | // Apply the typecasts. | |
147 | HeaderP = (Header *)Map.Data(); | |
5bf15716 | 148 | GrpP = (Group *)Map.Data(); |
578bfd0a | 149 | PkgP = (Package *)Map.Data(); |
dcb79bae | 150 | VerFileP = (VerFile *)Map.Data(); |
a52f938b | 151 | DescFileP = (DescFile *)Map.Data(); |
b07aeb1a | 152 | RlsFileP = (ReleaseFile *)Map.Data(); |
578bfd0a AL |
153 | PkgFileP = (PackageFile *)Map.Data(); |
154 | VerP = (Version *)Map.Data(); | |
a52f938b | 155 | DescP = (Description *)Map.Data(); |
578bfd0a AL |
156 | ProvideP = (Provides *)Map.Data(); |
157 | DepP = (Dependency *)Map.Data(); | |
71c9e95b | 158 | DepDataP = (DependencyData *)Map.Data(); |
578bfd0a AL |
159 | StrP = (char *)Map.Data(); |
160 | ||
a9fe5928 DK |
161 | if (Errorchecks == false) |
162 | return true; | |
163 | ||
b2e465d6 AL |
164 | if (Map.Size() == 0 || HeaderP == 0) |
165 | return _error->Error(_("Empty package cache")); | |
578bfd0a AL |
166 | |
167 | // Check the header | |
168 | Header DefHeader; | |
169 | if (HeaderP->Signature != DefHeader.Signature || | |
170 | HeaderP->Dirty == true) | |
b2e465d6 | 171 | return _error->Error(_("The package cache file is corrupted")); |
578bfd0a AL |
172 | |
173 | if (HeaderP->MajorVersion != DefHeader.MajorVersion || | |
174 | HeaderP->MinorVersion != DefHeader.MinorVersion || | |
175 | HeaderP->CheckSizes(DefHeader) == false) | |
b2e465d6 AL |
176 | return _error->Error(_("The package cache file is an incompatible version")); |
177 | ||
32ab4bd0 | 178 | if (HeaderP->VerSysName == 0 || HeaderP->Architecture == 0 || HeaderP->GetArchitectures() == 0) |
7a223b93 DK |
179 | return _error->Error(_("The package cache file is corrupted")); |
180 | ||
b2e465d6 | 181 | // Locate our VS.. |
7a223b93 | 182 | if ((VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0) |
db0db9fe | 183 | return _error->Error(_("This APT does not support the versioning system '%s'"),StrP + HeaderP->VerSysName); |
b2e465d6 | 184 | |
7a223b93 DK |
185 | // Check the architecture |
186 | std::vector<std::string> archs = APT::Configuration::getArchitectures(); | |
187 | std::vector<std::string>::const_iterator a = archs.begin(); | |
188 | std::string list = *a; | |
189 | for (++a; a != archs.end(); ++a) | |
190 | list.append(",").append(*a); | |
191 | if (_config->Find("APT::Architecture") != StrP + HeaderP->Architecture || | |
32ab4bd0 DK |
192 | list != StrP + HeaderP->GetArchitectures()) |
193 | return _error->Error(_("The package cache was built for different architectures: %s vs %s"), StrP + HeaderP->GetArchitectures(), list.c_str()); | |
7a223b93 | 194 | |
25c7a09d JAK |
195 | |
196 | auto hash = CacheHash(); | |
197 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
198 | std::clog << "Opened cache with hash " << hash << ", expecting " << HeaderP->CacheFileSize << "\n"; | |
199 | if (hash != HeaderP->CacheFileSize) | |
200 | return _error->Error(_("The package cache file is corrupted, it has the wrong hash")); | |
201 | ||
578bfd0a AL |
202 | return true; |
203 | } | |
204 | /*}}}*/ | |
205 | // Cache::Hash - Hash a string /*{{{*/ | |
206 | // --------------------------------------------------------------------- | |
207 | /* This is used to generate the hash entries for the HashTable. With my | |
208 | package list from bo this function gets 94% table usage on a 512 item | |
209 | table (480 used items) */ | |
eff0c22e JAK |
210 | map_id_t pkgCache::sHash(StringView Str) const |
211 | { | |
212 | uint32_t Hash = 5381; | |
213 | for (auto I = Str.begin(); I != Str.end(); ++I) | |
214 | Hash = 33 * Hash + tolower_ascii(*I); | |
215 | return Hash % HeaderP->GetHashTableSize(); | |
216 | } | |
4ad8619b | 217 | map_id_t pkgCache::sHash(const string &Str) const |
578bfd0a | 218 | { |
0748f03a | 219 | uint32_t Hash = 5381; |
f7f0d6c7 | 220 | for (string::const_iterator I = Str.begin(); I != Str.end(); ++I) |
38a5b1ce | 221 | Hash = 33 * Hash + tolower_ascii((signed char)*I); |
32ab4bd0 | 222 | return Hash % HeaderP->GetHashTableSize(); |
578bfd0a AL |
223 | } |
224 | ||
4ad8619b | 225 | map_id_t pkgCache::sHash(const char *Str) const |
578bfd0a | 226 | { |
0748f03a JAK |
227 | uint32_t Hash = 5381; |
228 | for (const char *I = Str; *I != 0; ++I) | |
38a5b1ce | 229 | Hash = 33 * Hash + tolower_ascii((signed char)*I); |
32ab4bd0 | 230 | return Hash % HeaderP->GetHashTableSize(); |
578bfd0a | 231 | } |
25c7a09d JAK |
232 | |
233 | uint32_t pkgCache::CacheHash() | |
234 | { | |
235 | pkgCache::Header header = {}; | |
236 | uLong adler = adler32(0L, Z_NULL, 0); | |
237 | ||
238 | if (Map.Size() < sizeof(header)) | |
239 | return adler; | |
240 | memcpy(&header, GetMap().Data(), sizeof(header)); | |
241 | ||
242 | header.Dirty = false; | |
243 | header.CacheFileSize = 0; | |
244 | ||
245 | adler = adler32(adler, | |
246 | reinterpret_cast<const unsigned char *>(&header), | |
247 | sizeof(header)); | |
248 | ||
249 | if (Map.Size() > sizeof(header)) { | |
250 | adler = adler32(adler, | |
251 | static_cast<const unsigned char *>(GetMap().Data()) + sizeof(header), | |
252 | GetMap().Size() - sizeof(header)); | |
253 | } | |
254 | ||
255 | return adler; | |
256 | } | |
8d4c859d | 257 | /*}}}*/ |
578bfd0a AL |
258 | // Cache::FindPkg - Locate a package by name /*{{{*/ |
259 | // --------------------------------------------------------------------- | |
260 | /* Returns 0 on error, pointer to the package otherwise */ | |
25396fb0 | 261 | pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) { |
eff0c22e JAK |
262 | return FindPkg(StringView(Name)); |
263 | } | |
264 | ||
265 | pkgCache::PkgIterator pkgCache::FindPkg(StringView Name) { | |
266 | auto const found = Name.find(':'); | |
25396fb0 | 267 | if (found == string::npos) |
6c9937da | 268 | return FindPkg(Name, "native"); |
eff0c22e | 269 | auto const Arch = Name.substr(found+1); |
8fec289a DK |
270 | /* Beware: This is specialcased to handle pkg:any in dependencies |
271 | as these are linked to virtual pkg:any named packages. | |
272 | If you want any arch from a pkg, use FindPkg(pkg,"any") */ | |
4d174dc8 DK |
273 | if (Arch == "any") |
274 | return FindPkg(Name, "any"); | |
275 | return FindPkg(Name.substr(0, found), Arch); | |
25396fb0 DK |
276 | } |
277 | /*}}}*/ | |
278 | // Cache::FindPkg - Locate a package by name /*{{{*/ | |
279 | // --------------------------------------------------------------------- | |
280 | /* Returns 0 on error, pointer to the package otherwise */ | |
8d4c859d | 281 | pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) { |
eff0c22e JAK |
282 | return FindPkg(StringView(Name), StringView(Arch)); |
283 | } | |
284 | ||
285 | pkgCache::PkgIterator pkgCache::FindPkg(StringView Name, StringView Arch) { | |
5bf15716 DK |
286 | /* We make a detour via the GrpIterator here as |
287 | on a multi-arch environment a group is easier to | |
288 | find than a package (less entries in the buckets) */ | |
289 | pkgCache::GrpIterator Grp = FindGrp(Name); | |
290 | if (Grp.end() == true) | |
291 | return PkgIterator(*this,0); | |
292 | ||
293 | return Grp.FindPkg(Arch); | |
294 | } | |
295 | /*}}}*/ | |
296 | // Cache::FindGrp - Locate a group by name /*{{{*/ | |
297 | // --------------------------------------------------------------------- | |
298 | /* Returns End-Pointer on error, pointer to the group otherwise */ | |
299 | pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) { | |
eff0c22e JAK |
300 | return FindGrp(StringView(Name)); |
301 | } | |
302 | ||
303 | pkgCache::GrpIterator pkgCache::FindGrp(StringView Name) { | |
5bf15716 DK |
304 | if (unlikely(Name.empty() == true)) |
305 | return GrpIterator(*this,0); | |
306 | ||
307 | // Look at the hash bucket for the group | |
32ab4bd0 | 308 | Group *Grp = GrpP + HeaderP->GrpHashTableP()[sHash(Name)]; |
5bf15716 | 309 | for (; Grp != GrpP; Grp = GrpP + Grp->Next) { |
60d523e2 | 310 | int const cmp = Name.compare(ViewString(Grp->Name)); |
aa0fe657 | 311 | if (cmp == 0) |
5bf15716 | 312 | return GrpIterator(*this, Grp); |
aa0fe657 DK |
313 | else if (cmp < 0) |
314 | break; | |
5bf15716 DK |
315 | } |
316 | ||
317 | return GrpIterator(*this,0); | |
578bfd0a AL |
318 | } |
319 | /*}}}*/ | |
b2e465d6 AL |
320 | // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/ |
321 | // --------------------------------------------------------------------- | |
322 | /* This returns a string representation of the dependency compare | |
323 | type in the weird debian style.. */ | |
324 | const char *pkgCache::CompTypeDeb(unsigned char Comp) | |
325 | { | |
69c2ecbd DK |
326 | const char * const Ops[] = {"","<=",">=","<<",">>","=","!="}; |
327 | if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0]))) | |
328 | return ""; | |
329 | return Ops[Comp & 0xF]; | |
b2e465d6 AL |
330 | } |
331 | /*}}}*/ | |
332 | // Cache::CompType - Return a string describing the compare type /*{{{*/ | |
333 | // --------------------------------------------------------------------- | |
69c2ecbd | 334 | /* This returns a string representation of the dependency compare |
b2e465d6 AL |
335 | type */ |
336 | const char *pkgCache::CompType(unsigned char Comp) | |
337 | { | |
69c2ecbd DK |
338 | const char * const Ops[] = {"","<=",">=","<",">","=","!="}; |
339 | if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0]))) | |
340 | return ""; | |
341 | return Ops[Comp & 0xF]; | |
b2e465d6 AL |
342 | } |
343 | /*}}}*/ | |
344 | // Cache::DepType - Return a string describing the dep type /*{{{*/ | |
345 | // --------------------------------------------------------------------- | |
346 | /* */ | |
347 | const char *pkgCache::DepType(unsigned char Type) | |
348 | { | |
349 | const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"), | |
350 | _("Recommends"),_("Conflicts"),_("Replaces"), | |
f8ae7e8b | 351 | _("Obsoletes"),_("Breaks"), _("Enhances")}; |
308c7d30 | 352 | if (Type < sizeof(Types)/sizeof(*Types)) |
b2e465d6 AL |
353 | return Types[Type]; |
354 | return ""; | |
355 | } | |
356 | /*}}}*/ | |
0149949b AL |
357 | // Cache::Priority - Convert a priority value to a string /*{{{*/ |
358 | // --------------------------------------------------------------------- | |
359 | /* */ | |
360 | const char *pkgCache::Priority(unsigned char Prio) | |
361 | { | |
2fcd25a9 | 362 | const char *Mapping[] = {0,_("required"),_("important"),_("standard"), |
b2e465d6 | 363 | _("optional"),_("extra")}; |
0149949b AL |
364 | if (Prio < _count(Mapping)) |
365 | return Mapping[Prio]; | |
366 | return 0; | |
367 | } | |
368 | /*}}}*/ | |
5bf15716 DK |
369 | // GrpIterator::FindPkg - Locate a package by arch /*{{{*/ |
370 | // --------------------------------------------------------------------- | |
371 | /* Returns an End-Pointer on error, pointer to the package otherwise */ | |
e841200b | 372 | pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const { |
eff0c22e JAK |
373 | return FindPkg(StringView(Arch)); |
374 | } | |
375 | pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(const char *Arch) const { | |
376 | return FindPkg(StringView(Arch)); | |
377 | } | |
378 | pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(StringView Arch) const { | |
5bf15716 DK |
379 | if (unlikely(IsGood() == false || S->FirstPackage == 0)) |
380 | return PkgIterator(*Owner, 0); | |
381 | ||
60dcec6d | 382 | /* If we accept any package we simply return the "first" |
8fec289a | 383 | package in this group */ |
60dcec6d DK |
384 | if (Arch == "any") |
385 | return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage); | |
8fec289a DK |
386 | if (Arch == "native" || Arch == "all") |
387 | Arch = Owner->NativeArch(); | |
5bf15716 | 388 | |
5d1e330d | 389 | // Iterate over the list to find the matching arch |
5bf15716 | 390 | for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP; |
32ab4bd0 | 391 | Pkg = Owner->PkgP + Pkg->NextPackage) { |
60d523e2 | 392 | if (Arch == Owner->ViewString(Pkg->Arch)) |
5bf15716 DK |
393 | return PkgIterator(*Owner, Pkg); |
394 | if ((Owner->PkgP + S->LastPackage) == Pkg) | |
395 | break; | |
396 | } | |
397 | ||
bd2fb30a DK |
398 | return PkgIterator(*Owner, 0); |
399 | } | |
400 | /*}}}*/ | |
401 | // GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/ | |
402 | // --------------------------------------------------------------------- | |
403 | /* Returns an End-Pointer on error, pointer to the package otherwise */ | |
3db58cf4 | 404 | pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual) const { |
eff0c22e | 405 | pkgCache::PkgIterator Pkg = FindPkg(StringView("native", 6)); |
3db58cf4 | 406 | if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) |
bd2fb30a DK |
407 | return Pkg; |
408 | ||
409 | std::vector<std::string> const archs = APT::Configuration::getArchitectures(); | |
410 | for (std::vector<std::string>::const_iterator a = archs.begin(); | |
411 | a != archs.end(); ++a) { | |
412 | Pkg = FindPkg(*a); | |
3db58cf4 | 413 | if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) |
bd2fb30a DK |
414 | return Pkg; |
415 | } | |
c919ad6e | 416 | // packages without an architecture |
eff0c22e | 417 | Pkg = FindPkg(StringView("none", 4)); |
c919ad6e DK |
418 | if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) |
419 | return Pkg; | |
bd2fb30a | 420 | |
3db58cf4 DK |
421 | if (PreferNonVirtual == true) |
422 | return FindPreferredPkg(false); | |
5bf15716 DK |
423 | return PkgIterator(*Owner, 0); |
424 | } | |
425 | /*}}}*/ | |
426 | // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/ | |
427 | // --------------------------------------------------------------------- | |
428 | /* Returns an End-Pointer on error, pointer to the package otherwise. | |
c408e01e DK |
429 | We can't simply ++ to the next as the next package of the last will |
430 | be from a different group (with the same hash value) */ | |
e841200b | 431 | pkgCache::PkgIterator pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator const &LastPkg) const { |
5bf15716 DK |
432 | if (unlikely(IsGood() == false || S->FirstPackage == 0 || |
433 | LastPkg.end() == true)) | |
434 | return PkgIterator(*Owner, 0); | |
435 | ||
c408e01e DK |
436 | if (S->LastPackage == LastPkg.Index()) |
437 | return PkgIterator(*Owner, 0); | |
5bf15716 | 438 | |
32ab4bd0 | 439 | return PkgIterator(*Owner, Owner->PkgP + LastPkg->NextPackage); |
5bf15716 DK |
440 | } |
441 | /*}}}*/ | |
71c9e95b | 442 | // GrpIterator::operator++ - Prefix incr /*{{{*/ |
25396fb0 DK |
443 | // --------------------------------------------------------------------- |
444 | /* This will advance to the next logical group in the hash table. */ | |
3707fd4f | 445 | pkgCache::GrpIterator& pkgCache::GrpIterator::operator++() |
25396fb0 DK |
446 | { |
447 | // Follow the current links | |
448 | if (S != Owner->GrpP) | |
449 | S = Owner->GrpP + S->Next; | |
450 | ||
451 | // Follow the hash table | |
32ab4bd0 | 452 | while (S == Owner->GrpP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize()) |
25396fb0 | 453 | { |
71c9e95b | 454 | ++HashIndex; |
32ab4bd0 | 455 | S = Owner->GrpP + Owner->HeaderP->GrpHashTableP()[HashIndex]; |
25396fb0 | 456 | } |
3707fd4f | 457 | return *this; |
d3e8fbb3 | 458 | } |
f55a958f | 459 | /*}}}*/ |
71c9e95b | 460 | // PkgIterator::operator++ - Prefix incr /*{{{*/ |
578bfd0a AL |
461 | // --------------------------------------------------------------------- |
462 | /* This will advance to the next logical package in the hash table. */ | |
71c9e95b | 463 | pkgCache::PkgIterator& pkgCache::PkgIterator::operator++() |
578bfd0a AL |
464 | { |
465 | // Follow the current links | |
773e2c1f | 466 | if (S != Owner->PkgP) |
32ab4bd0 | 467 | S = Owner->PkgP + S->NextPackage; |
b2e465d6 | 468 | |
578bfd0a | 469 | // Follow the hash table |
32ab4bd0 | 470 | while (S == Owner->PkgP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize()) |
578bfd0a | 471 | { |
71c9e95b | 472 | ++HashIndex; |
32ab4bd0 | 473 | S = Owner->PkgP + Owner->HeaderP->PkgHashTableP()[HashIndex]; |
578bfd0a | 474 | } |
3707fd4f | 475 | return *this; |
d3e8fbb3 | 476 | } |
578bfd0a | 477 | /*}}}*/ |
71c9e95b DK |
478 | pkgCache::DepIterator& pkgCache::DepIterator::operator++() /*{{{*/ |
479 | { | |
480 | if (S == Owner->DepP) | |
481 | return *this; | |
482 | S = Owner->DepP + (Type == DepVer ? S->NextDepends : S->NextRevDepends); | |
483 | if (S == Owner->DepP) | |
484 | S2 = Owner->DepDataP; | |
485 | else | |
486 | S2 = Owner->DepDataP + S->DependencyData; | |
487 | return *this; | |
488 | } | |
489 | /*}}}*/ | |
578bfd0a AL |
490 | // PkgIterator::State - Check the State of the package /*{{{*/ |
491 | // --------------------------------------------------------------------- | |
492 | /* By this we mean if it is either cleanly installed or cleanly removed. */ | |
493 | pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const | |
d38b7b3d | 494 | { |
773e2c1f DK |
495 | if (S->InstState == pkgCache::State::ReInstReq || |
496 | S->InstState == pkgCache::State::HoldReInstReq) | |
c7c1b0f6 AL |
497 | return NeedsUnpack; |
498 | ||
773e2c1f DK |
499 | if (S->CurrentState == pkgCache::State::UnPacked || |
500 | S->CurrentState == pkgCache::State::HalfConfigured) | |
c6aa14e4 MV |
501 | // we leave triggers alone complettely. dpkg deals with |
502 | // them in a hard-to-predict manner and if they get | |
503 | // resolved by dpkg before apt run dpkg --configure on | |
504 | // the TriggersPending package dpkg returns a error | |
09fab244 | 505 | //Pkg->CurrentState == pkgCache::State::TriggersAwaited |
c6aa14e4 | 506 | //Pkg->CurrentState == pkgCache::State::TriggersPending) |
578bfd0a AL |
507 | return NeedsConfigure; |
508 | ||
773e2c1f DK |
509 | if (S->CurrentState == pkgCache::State::HalfInstalled || |
510 | S->InstState != pkgCache::State::Ok) | |
578bfd0a AL |
511 | return NeedsUnpack; |
512 | ||
513 | return NeedsNothing; | |
514 | } | |
515 | /*}}}*/ | |
af29ffb4 MV |
516 | // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/ |
517 | // --------------------------------------------------------------------- | |
518 | /* Return string representing of the candidate version. */ | |
519 | const char * | |
d3e8fbb3 | 520 | pkgCache::PkgIterator::CandVersion() const |
af29ffb4 MV |
521 | { |
522 | //TargetVer is empty, so don't use it. | |
749eb4cf | 523 | VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this); |
af29ffb4 MV |
524 | if (version.IsGood()) |
525 | return version.VerStr(); | |
526 | return 0; | |
d3e8fbb3 | 527 | } |
af29ffb4 MV |
528 | /*}}}*/ |
529 | // PkgIterator::CurVersion - Returns the current version string /*{{{*/ | |
530 | // --------------------------------------------------------------------- | |
531 | /* Return string representing of the current version. */ | |
532 | const char * | |
d3e8fbb3 | 533 | pkgCache::PkgIterator::CurVersion() const |
af29ffb4 MV |
534 | { |
535 | VerIterator version = CurrentVer(); | |
536 | if (version.IsGood()) | |
537 | return CurrentVer().VerStr(); | |
538 | return 0; | |
d3e8fbb3 | 539 | } |
af29ffb4 MV |
540 | /*}}}*/ |
541 | // ostream operator to handle string representation of a package /*{{{*/ | |
542 | // --------------------------------------------------------------------- | |
543 | /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section) | |
1e3f4083 | 544 | Note that the characters <|>() are all literal above. Versions will be omitted |
af29ffb4 MV |
545 | if they provide no new information (e.g. there is no newer version than candidate) |
546 | If no version and/or section can be found "none" is used. */ | |
547 | std::ostream& | |
8f3ba4e8 | 548 | operator<<(std::ostream& out, pkgCache::PkgIterator Pkg) |
af29ffb4 MV |
549 | { |
550 | if (Pkg.end() == true) | |
551 | return out << "invalid package"; | |
552 | ||
553 | string current = string(Pkg.CurVersion() == 0 ? "none" : Pkg.CurVersion()); | |
554 | string candidate = string(Pkg.CandVersion() == 0 ? "none" : Pkg.CandVersion()); | |
555 | string newest = string(Pkg.VersionList().end() ? "none" : Pkg.VersionList().VerStr()); | |
556 | ||
5dd4c8b8 | 557 | out << Pkg.Name() << " [ " << Pkg.Arch() << " ] < " << current; |
af29ffb4 MV |
558 | if (current != candidate) |
559 | out << " -> " << candidate; | |
560 | if ( newest != "none" && candidate != newest) | |
561 | out << " | " << newest; | |
7a669774 DK |
562 | if (Pkg->VersionList == 0) |
563 | out << " > ( none )"; | |
564 | else | |
565 | out << " > ( " << string(Pkg.VersionList().Section()==0?"unknown":Pkg.VersionList().Section()) << " )"; | |
af29ffb4 MV |
566 | return out; |
567 | } | |
568 | /*}}}*/ | |
75ce2062 DK |
569 | // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/ |
570 | // --------------------------------------------------------------------- | |
571 | /* Returns a name:arch string */ | |
572 | std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const | |
573 | { | |
574 | string fullname = Name(); | |
575 | if (Pretty == false || | |
f6ce7ffc | 576 | (strcmp(Arch(), "all") != 0 && strcmp(Arch(), "any") != 0 && |
959470da | 577 | strcmp(Owner->NativeArch(), Arch()) != 0)) |
75ce2062 DK |
578 | return fullname.append(":").append(Arch()); |
579 | return fullname; | |
580 | } | |
581 | /*}}}*/ | |
578bfd0a AL |
582 | // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/ |
583 | // --------------------------------------------------------------------- | |
584 | /* Currently critical deps are defined as depends, predepends and | |
308c7d30 | 585 | conflicts (including dpkg's Breaks fields). */ |
e841200b | 586 | bool pkgCache::DepIterator::IsCritical() const |
578bfd0a | 587 | { |
359e46db | 588 | if (IsNegative() == true || |
71c9e95b DK |
589 | S2->Type == pkgCache::Dep::Depends || |
590 | S2->Type == pkgCache::Dep::PreDepends) | |
578bfd0a AL |
591 | return true; |
592 | return false; | |
593 | } | |
594 | /*}}}*/ | |
df77d8a5 DK |
595 | // DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/ |
596 | // --------------------------------------------------------------------- | |
597 | /* Some dependencies are positive like Depends and Recommends, others | |
598 | are negative like Conflicts which can and should be handled differently */ | |
599 | bool pkgCache::DepIterator::IsNegative() const | |
600 | { | |
71c9e95b DK |
601 | return S2->Type == Dep::DpkgBreaks || |
602 | S2->Type == Dep::Conflicts || | |
603 | S2->Type == Dep::Obsoletes; | |
df77d8a5 DK |
604 | } |
605 | /*}}}*/ | |
578bfd0a AL |
606 | // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/ |
607 | // --------------------------------------------------------------------- | |
608 | /* This intellegently looks at dep target packages and tries to figure | |
609 | out which package should be used. This is needed to nicely handle | |
610 | provide mapping. If the target package has no other providing packages | |
611 | then it returned. Otherwise the providing list is looked at to | |
612 | see if there is one one unique providing package if so it is returned. | |
613 | Otherwise true is returned and the target package is set. The return | |
b2e465d6 AL |
614 | result indicates whether the node should be expandable |
615 | ||
616 | In Conjunction with the DepCache the value of Result may not be | |
617 | super-good since the policy may have made it uninstallable. Using | |
618 | AllTargets is better in this case. */ | |
e841200b | 619 | bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const |
578bfd0a AL |
620 | { |
621 | Result = TargetPkg(); | |
622 | ||
623 | // No provides at all | |
624 | if (Result->ProvidesList == 0) | |
625 | return false; | |
626 | ||
627 | // There is the Base package and the providing ones which is at least 2 | |
628 | if (Result->VersionList != 0) | |
629 | return true; | |
630 | ||
631 | /* We have to skip over indirect provisions of the package that | |
632 | owns the dependency. For instance, if libc5-dev depends on the | |
633 | virtual package libc-dev which is provided by libc5-dev and libc6-dev | |
634 | we must ignore libc5-dev when considering the provides list. */ | |
635 | PrvIterator PStart = Result.ProvidesList(); | |
f7f0d6c7 | 636 | for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); ++PStart); |
578bfd0a AL |
637 | |
638 | // Nothing but indirect self provides | |
639 | if (PStart.end() == true) | |
640 | return false; | |
641 | ||
642 | // Check for single packages in the provides list | |
643 | PrvIterator P = PStart; | |
f7f0d6c7 | 644 | for (; P.end() != true; ++P) |
578bfd0a AL |
645 | { |
646 | // Skip over self provides | |
647 | if (P.OwnerPkg() == ParentPkg()) | |
648 | continue; | |
649 | if (PStart.OwnerPkg() != P.OwnerPkg()) | |
650 | break; | |
651 | } | |
b2e465d6 AL |
652 | |
653 | Result = PStart.OwnerPkg(); | |
578bfd0a AL |
654 | |
655 | // Check for non dups | |
656 | if (P.end() != true) | |
657 | return true; | |
b2e465d6 | 658 | |
578bfd0a AL |
659 | return false; |
660 | } | |
661 | /*}}}*/ | |
662 | // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/ | |
663 | // --------------------------------------------------------------------- | |
b2e465d6 | 664 | /* This is a more useful version of TargetPkg() that follows versioned |
578bfd0a | 665 | provides. It includes every possible package-version that could satisfy |
fbfb2a7c AL |
666 | the dependency. The last item in the list has a 0. The resulting pointer |
667 | must be delete [] 'd */ | |
e841200b | 668 | pkgCache::Version **pkgCache::DepIterator::AllTargets() const |
578bfd0a AL |
669 | { |
670 | Version **Res = 0; | |
671 | unsigned long Size =0; | |
672 | while (1) | |
673 | { | |
674 | Version **End = Res; | |
675 | PkgIterator DPkg = TargetPkg(); | |
676 | ||
677 | // Walk along the actual package providing versions | |
f7f0d6c7 | 678 | for (VerIterator I = DPkg.VersionList(); I.end() == false; ++I) |
578bfd0a | 679 | { |
85434114 | 680 | if (IsIgnorable(I.ParentPkg()) == true) |
578bfd0a | 681 | continue; |
887c6940 | 682 | if (IsSatisfied(I) == false) |
578bfd0a | 683 | continue; |
85434114 | 684 | |
578bfd0a AL |
685 | Size++; |
686 | if (Res != 0) | |
687 | *End++ = I; | |
688 | } | |
689 | ||
690 | // Follow all provides | |
f7f0d6c7 | 691 | for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; ++I) |
578bfd0a | 692 | { |
85434114 | 693 | if (IsIgnorable(I) == true) |
578bfd0a | 694 | continue; |
887c6940 | 695 | if (IsSatisfied(I) == false) |
85434114 | 696 | continue; |
5f909b67 | 697 | |
578bfd0a AL |
698 | Size++; |
699 | if (Res != 0) | |
700 | *End++ = I.OwnerVer(); | |
701 | } | |
702 | ||
703 | // Do it again and write it into the array | |
704 | if (Res == 0) | |
705 | { | |
706 | Res = new Version *[Size+1]; | |
707 | Size = 0; | |
708 | } | |
709 | else | |
710 | { | |
711 | *End = 0; | |
712 | break; | |
713 | } | |
714 | } | |
715 | ||
716 | return Res; | |
717 | } | |
718 | /*}}}*/ | |
43d017d6 AL |
719 | // DepIterator::GlobOr - Compute an OR group /*{{{*/ |
720 | // --------------------------------------------------------------------- | |
721 | /* This Takes an iterator, iterates past the current dependency grouping | |
722 | and returns Start and End so that so End is the final element | |
723 | in the group, if End == Start then D is End++ and End is the | |
724 | dependency D was pointing to. Use in loops to iterate sensibly. */ | |
725 | void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End) | |
726 | { | |
727 | // Compute a single dependency element (glob or) | |
728 | Start = *this; | |
729 | End = *this; | |
018f1533 | 730 | for (bool LastOR = true; end() == false && LastOR == true;) |
43d017d6 | 731 | { |
71c9e95b | 732 | LastOR = (S2->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; |
3707fd4f | 733 | ++(*this); |
43d017d6 AL |
734 | if (LastOR == true) |
735 | End = (*this); | |
736 | } | |
737 | } | |
738 | /*}}}*/ | |
85434114 DK |
739 | // DepIterator::IsIgnorable - should this packag/providr be ignored? /*{{{*/ |
740 | // --------------------------------------------------------------------- | |
741 | /* Deps like self-conflicts should be ignored as well as implicit conflicts | |
742 | on virtual packages. */ | |
fd23676e | 743 | bool pkgCache::DepIterator::IsIgnorable(PkgIterator const &PT) const |
85434114 | 744 | { |
021626db DK |
745 | if (IsNegative() == false) |
746 | return false; | |
747 | ||
fd23676e | 748 | pkgCache::PkgIterator const PP = ParentPkg(); |
021626db DK |
749 | if (PP->Group != PT->Group) |
750 | return false; | |
751 | // self-conflict | |
752 | if (PP == PT) | |
753 | return true; | |
fd23676e | 754 | pkgCache::VerIterator const PV = ParentVer(); |
021626db DK |
755 | // ignore group-conflict on a M-A:same package - but not our implicit dependencies |
756 | // so that we can have M-A:same packages conflicting with their own real name | |
757 | if ((PV->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) | |
8c7af4d4 | 758 | return IsMultiArchImplicit() == false; |
85434114 DK |
759 | |
760 | return false; | |
761 | } | |
762 | bool pkgCache::DepIterator::IsIgnorable(PrvIterator const &Prv) const | |
763 | { | |
764 | if (IsNegative() == false) | |
765 | return false; | |
766 | ||
767 | PkgIterator const Pkg = ParentPkg(); | |
768 | /* Provides may never be applied against the same package (or group) | |
769 | if it is a conflicts. See the comment above. */ | |
770 | if (Prv.OwnerPkg()->Group == Pkg->Group) | |
771 | return true; | |
772 | // Implicit group-conflicts should not be applied on providers of other groups | |
8c7af4d4 | 773 | if (IsMultiArchImplicit() && Prv.OwnerPkg()->Group != Pkg->Group) |
85434114 DK |
774 | return true; |
775 | ||
776 | return false; | |
777 | } | |
778 | /*}}}*/ | |
887c6940 DK |
779 | // DepIterator::IsSatisfied - check if a version satisfied the dependency /*{{{*/ |
780 | bool pkgCache::DepIterator::IsSatisfied(VerIterator const &Ver) const | |
781 | { | |
71c9e95b | 782 | return Owner->VS->CheckDep(Ver.VerStr(),S2->CompareOp,TargetVer()); |
887c6940 DK |
783 | } |
784 | bool pkgCache::DepIterator::IsSatisfied(PrvIterator const &Prv) const | |
785 | { | |
71c9e95b | 786 | return Owner->VS->CheckDep(Prv.ProvideVersion(),S2->CompareOp,TargetVer()); |
887c6940 DK |
787 | } |
788 | /*}}}*/ | |
8c7af4d4 DK |
789 | // DepIterator::IsImplicit - added by the cache generation /*{{{*/ |
790 | bool pkgCache::DepIterator::IsImplicit() const | |
791 | { | |
792 | if (IsMultiArchImplicit() == true) | |
793 | return true; | |
794 | if (IsNegative() || S2->Type == pkgCache::Dep::Replaces) | |
795 | { | |
796 | if ((S2->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific && | |
797 | strcmp(ParentPkg().Arch(), TargetPkg().Arch()) != 0) | |
798 | return true; | |
799 | } | |
800 | return false; | |
801 | } | |
802 | /*}}}*/ | |
47f6d1b7 DK |
803 | // ostream operator to handle string representation of a dependecy /*{{{*/ |
804 | // --------------------------------------------------------------------- | |
805 | /* */ | |
8f3ba4e8 | 806 | std::ostream& operator<<(std::ostream& out, pkgCache::DepIterator D) |
47f6d1b7 DK |
807 | { |
808 | if (D.end() == true) | |
809 | return out << "invalid dependency"; | |
810 | ||
811 | pkgCache::PkgIterator P = D.ParentPkg(); | |
812 | pkgCache::PkgIterator T = D.TargetPkg(); | |
813 | ||
814 | out << (P.end() ? "invalid pkg" : P.FullName(false)) << " " << D.DepType() | |
815 | << " on "; | |
816 | if (T.end() == true) | |
817 | out << "invalid pkg"; | |
818 | else | |
819 | out << T; | |
820 | ||
821 | if (D->Version != 0) | |
822 | out << " (" << D.CompType() << " " << D.TargetVer() << ")"; | |
823 | ||
824 | return out; | |
825 | } | |
826 | /*}}}*/ | |
578bfd0a AL |
827 | // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/ |
828 | // --------------------------------------------------------------------- | |
829 | /* This just looks over the version list to see if B is listed before A. In | |
830 | most cases this will return in under 4 checks, ver lists are short. */ | |
831 | int pkgCache::VerIterator::CompareVer(const VerIterator &B) const | |
832 | { | |
833 | // Check if they are equal | |
834 | if (*this == B) | |
835 | return 0; | |
836 | if (end() == true) | |
837 | return -1; | |
838 | if (B.end() == true) | |
839 | return 1; | |
840 | ||
841 | /* Start at A and look for B. If B is found then A > B otherwise | |
842 | B was before A so A < B */ | |
843 | VerIterator I = *this; | |
f7f0d6c7 | 844 | for (;I.end() == false; ++I) |
578bfd0a AL |
845 | if (I == B) |
846 | return 1; | |
847 | return -1; | |
848 | } | |
849 | /*}}}*/ | |
b518cca6 AL |
850 | // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/ |
851 | // --------------------------------------------------------------------- | |
852 | /* */ | |
0e6fe58e | 853 | APT_PURE bool pkgCache::VerIterator::Downloadable() const |
b518cca6 AL |
854 | { |
855 | VerFileIterator Files = FileList(); | |
f7f0d6c7 | 856 | for (; Files.end() == false; ++Files) |
b07aeb1a | 857 | if (Files.File().Flagged(pkgCache::Flag::NotSource) == false) |
b518cca6 AL |
858 | return true; |
859 | return false; | |
860 | } | |
861 | /*}}}*/ | |
3c124dde AL |
862 | // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/ |
863 | // --------------------------------------------------------------------- | |
864 | /* This checks to see if any of the versions files are not NotAutomatic. | |
865 | True if this version is selectable for automatic installation. */ | |
0e6fe58e | 866 | APT_PURE bool pkgCache::VerIterator::Automatic() const |
3c124dde AL |
867 | { |
868 | VerFileIterator Files = FileList(); | |
f7f0d6c7 | 869 | for (; Files.end() == false; ++Files) |
5ed56f93 | 870 | // Do not check ButAutomaticUpgrades here as it is kind of automatic… |
b07aeb1a | 871 | if (Files.File().Flagged(pkgCache::Flag::NotAutomatic) == false) |
3c124dde AL |
872 | return true; |
873 | return false; | |
874 | } | |
875 | /*}}}*/ | |
876 | // VerIterator::NewestFile - Return the newest file version relation /*{{{*/ | |
877 | // --------------------------------------------------------------------- | |
878 | /* This looks at the version numbers associated with all of the sources | |
879 | this version is in and returns the highest.*/ | |
880 | pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const | |
881 | { | |
882 | VerFileIterator Files = FileList(); | |
883 | VerFileIterator Highest = Files; | |
f7f0d6c7 | 884 | for (; Files.end() == false; ++Files) |
3c124dde | 885 | { |
b2e465d6 | 886 | if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0) |
3c124dde AL |
887 | Highest = Files; |
888 | } | |
889 | ||
890 | return Highest; | |
891 | } | |
892 | /*}}}*/ | |
b2e465d6 AL |
893 | // VerIterator::RelStr - Release description string /*{{{*/ |
894 | // --------------------------------------------------------------------- | |
895 | /* This describes the version from a release-centric manner. The output is a | |
896 | list of Label:Version/Archive */ | |
7f8c0eed DK |
897 | static std::string PkgFileIteratorToRelString(pkgCache::PkgFileIterator const &File) |
898 | { | |
899 | std::string Res; | |
900 | if (File.Label() != 0) | |
901 | Res = Res + File.Label() + ':'; | |
902 | ||
903 | if (File.Archive() != 0) | |
904 | { | |
905 | if (File.Version() == 0) | |
906 | Res += File.Archive(); | |
907 | else | |
908 | Res = Res + File.Version() + '/' + File.Archive(); | |
909 | } | |
910 | else | |
911 | { | |
912 | // No release file, print the host name that this came from | |
913 | if (File.Site() == 0 || File.Site()[0] == 0) | |
914 | Res += "localhost"; | |
915 | else | |
916 | Res += File.Site(); | |
917 | } | |
918 | return Res; | |
919 | } | |
d4489d49 | 920 | string pkgCache::VerIterator::RelStr() const |
b2e465d6 | 921 | { |
7f8c0eed | 922 | std::vector<std::string> RelStrs; |
f7f0d6c7 | 923 | for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; ++I) |
b2e465d6 AL |
924 | { |
925 | // Do not print 'not source' entries' | |
b07aeb1a DK |
926 | pkgCache::PkgFileIterator const File = I.File(); |
927 | if (File.Flagged(pkgCache::Flag::NotSource)) | |
b2e465d6 AL |
928 | continue; |
929 | ||
7f8c0eed DK |
930 | std::string const RS = PkgFileIteratorToRelString(File); |
931 | if (std::find(RelStrs.begin(), RelStrs.end(), RS) != RelStrs.end()) | |
b2e465d6 | 932 | continue; |
b2e465d6 | 933 | |
7f8c0eed DK |
934 | RelStrs.push_back(RS); |
935 | } | |
936 | std::ostringstream os; | |
937 | if (likely(RelStrs.empty() == false)) | |
938 | { | |
939 | std::copy(RelStrs.begin(), RelStrs.end()-1, std::ostream_iterator<std::string>(os, ", ")); | |
940 | os << *RelStrs.rbegin(); | |
5dd4c8b8 | 941 | } |
857e9c13 | 942 | if (S->ParentPkg != 0) |
7f8c0eed DK |
943 | os << " [" << Arch() << "]"; |
944 | return os.str(); | |
b2e465d6 AL |
945 | } |
946 | /*}}}*/ | |
7a948ec7 DK |
947 | // VerIterator::MultiArchType - string representing MultiArch flag /*{{{*/ |
948 | const char * pkgCache::VerIterator::MultiArchType() const | |
949 | { | |
950 | if ((S->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) | |
951 | return "same"; | |
952 | else if ((S->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) | |
953 | return "foreign"; | |
954 | else if ((S->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) | |
955 | return "allowed"; | |
956 | return "none"; | |
957 | } | |
958 | /*}}}*/ | |
b07aeb1a | 959 | // RlsFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/ |
578bfd0a AL |
960 | // --------------------------------------------------------------------- |
961 | /* This stats the file and compares its stats with the ones that were | |
b07aeb1a | 962 | stored during generation. Date checks should probably also be |
578bfd0a | 963 | included here. */ |
b07aeb1a | 964 | bool pkgCache::RlsFileIterator::IsOk() |
578bfd0a AL |
965 | { |
966 | struct stat Buf; | |
967 | if (stat(FileName(),&Buf) != 0) | |
968 | return false; | |
969 | ||
773e2c1f | 970 | if (Buf.st_size != (signed)S->Size || Buf.st_mtime != S->mtime) |
578bfd0a AL |
971 | return false; |
972 | ||
973 | return true; | |
974 | } | |
975 | /*}}}*/ | |
b07aeb1a DK |
976 | // RlsFileIterator::RelStr - Return the release string /*{{{*/ |
977 | string pkgCache::RlsFileIterator::RelStr() | |
af87ab54 AL |
978 | { |
979 | string Res; | |
980 | if (Version() != 0) | |
981 | Res = Res + (Res.empty() == true?"v=":",v=") + Version(); | |
982 | if (Origin() != 0) | |
983 | Res = Res + (Res.empty() == true?"o=":",o=") + Origin(); | |
984 | if (Archive() != 0) | |
985 | Res = Res + (Res.empty() == true?"a=":",a=") + Archive(); | |
efc487fb DK |
986 | if (Codename() != 0) |
987 | Res = Res + (Res.empty() == true?"n=":",n=") + Codename(); | |
af87ab54 AL |
988 | if (Label() != 0) |
989 | Res = Res + (Res.empty() == true?"l=":",l=") + Label(); | |
b07aeb1a DK |
990 | return Res; |
991 | } | |
992 | /*}}}*/ | |
993 | // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/ | |
994 | // --------------------------------------------------------------------- | |
995 | /* This stats the file and compares its stats with the ones that were | |
996 | stored during generation. Date checks should probably also be | |
997 | included here. */ | |
998 | bool pkgCache::PkgFileIterator::IsOk() | |
999 | { | |
1000 | struct stat Buf; | |
1001 | if (stat(FileName(),&Buf) != 0) | |
1002 | return false; | |
1003 | ||
1004 | if (Buf.st_size != (signed)S->Size || Buf.st_mtime != S->mtime) | |
1005 | return false; | |
1006 | ||
1007 | return true; | |
1008 | } | |
1009 | /*}}}*/ | |
1010 | string pkgCache::PkgFileIterator::RelStr() /*{{{*/ | |
1011 | { | |
1012 | std::string Res; | |
1013 | if (ReleaseFile() == 0) | |
1014 | { | |
1015 | if (Component() != 0) | |
1016 | Res = Res + (Res.empty() == true?"a=":",a=") + Component(); | |
1017 | } | |
1018 | else | |
1019 | { | |
1020 | Res = ReleaseFile().RelStr(); | |
1021 | if (Component() != 0) | |
1022 | Res = Res + (Res.empty() == true?"c=":",c=") + Component(); | |
1023 | } | |
5dd4c8b8 DK |
1024 | if (Architecture() != 0) |
1025 | Res = Res + (Res.empty() == true?"b=":",b=") + Architecture(); | |
af87ab54 AL |
1026 | return Res; |
1027 | } | |
1028 | /*}}}*/ | |
012b102a MV |
1029 | // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/ |
1030 | // --------------------------------------------------------------------- | |
d3e8fbb3 | 1031 | /* return a DescIter for the current locale or the default if none is |
012b102a MV |
1032 | * found |
1033 | */ | |
1034 | pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const | |
1035 | { | |
45df0ad2 DK |
1036 | std::vector<string> const lang = APT::Configuration::getLanguages(); |
1037 | for (std::vector<string>::const_iterator l = lang.begin(); | |
f7f0d6c7 | 1038 | l != lang.end(); ++l) |
45df0ad2 | 1039 | { |
4b625b95 DK |
1040 | pkgCache::DescIterator Desc = DescriptionList(); |
1041 | for (; Desc.end() == false; ++Desc) | |
0e7c3313 | 1042 | if (*l == Desc.LanguageCode()) |
45df0ad2 | 1043 | break; |
4b625b95 | 1044 | if (Desc.end() == true) |
0e7c3313 DK |
1045 | { |
1046 | if (*l == "en") | |
1047 | { | |
1048 | Desc = DescriptionList(); | |
1049 | for (; Desc.end() == false; ++Desc) | |
1050 | if (strcmp(Desc.LanguageCode(), "") == 0) | |
1051 | break; | |
1052 | if (Desc.end() == true) | |
1053 | continue; | |
1054 | } | |
1055 | else | |
1056 | continue; | |
1057 | } | |
45df0ad2 DK |
1058 | return Desc; |
1059 | } | |
4b625b95 DK |
1060 | for (pkgCache::DescIterator Desc = DescriptionList(); |
1061 | Desc.end() == false; ++Desc) | |
1062 | if (strcmp(Desc.LanguageCode(), "") == 0) | |
1063 | return Desc; | |
45df0ad2 | 1064 | return DescriptionList(); |
d3e8fbb3 | 1065 | } |
012b102a MV |
1066 | |
1067 | /*}}}*/ | |
c8a4ce6c DK |
1068 | |
1069 | pkgCache::~pkgCache() {} |