]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: pkgcache.cc,v 1.37 2003/02/10 01:40:58 doogie Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Package Cache - Accessor code for the cache | |
7 | ||
8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of | |
9 | this format. Also be sure to keep that file up-to-date!! | |
10 | ||
11 | This is the general utility functions for cache managment. They provide | |
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 /*{{{*/ | |
23 | #include <apt-pkg/pkgcache.h> | |
24 | #include <apt-pkg/policy.h> | |
25 | #include <apt-pkg/indexfile.h> | |
26 | #include <apt-pkg/version.h> | |
27 | #include <apt-pkg/error.h> | |
28 | #include <apt-pkg/strutl.h> | |
29 | #include <apt-pkg/configuration.h> | |
30 | ||
31 | #include <apti18n.h> | |
32 | ||
33 | #include <string> | |
34 | #include <sys/stat.h> | |
35 | #include <unistd.h> | |
36 | ||
37 | #include <ctype.h> | |
38 | /*}}}*/ | |
39 | ||
40 | using std::string; | |
41 | ||
42 | ||
43 | // Cache::Header::Header - Constructor /*{{{*/ | |
44 | // --------------------------------------------------------------------- | |
45 | /* Simply initialize the header */ | |
46 | pkgCache::Header::Header() | |
47 | { | |
48 | Signature = 0x98FE76DC; | |
49 | ||
50 | /* Whenever the structures change the major version should be bumped, | |
51 | whenever the generator changes the minor version should be bumped. */ | |
52 | MajorVersion = 7; | |
53 | MinorVersion = 0; | |
54 | Dirty = false; | |
55 | ||
56 | HeaderSz = sizeof(pkgCache::Header); | |
57 | PackageSz = sizeof(pkgCache::Package); | |
58 | PackageFileSz = sizeof(pkgCache::PackageFile); | |
59 | VersionSz = sizeof(pkgCache::Version); | |
60 | DescriptionSz = sizeof(pkgCache::Description); | |
61 | DependencySz = sizeof(pkgCache::Dependency); | |
62 | ProvidesSz = sizeof(pkgCache::Provides); | |
63 | VerFileSz = sizeof(pkgCache::VerFile); | |
64 | DescFileSz = sizeof(pkgCache::DescFile); | |
65 | ||
66 | PackageCount = 0; | |
67 | VersionCount = 0; | |
68 | DescriptionCount = 0; | |
69 | DependsCount = 0; | |
70 | PackageFileCount = 0; | |
71 | VerFileCount = 0; | |
72 | DescFileCount = 0; | |
73 | ProvidesCount = 0; | |
74 | MaxVerFileSize = 0; | |
75 | MaxDescFileSize = 0; | |
76 | ||
77 | FileList = 0; | |
78 | StringList = 0; | |
79 | VerSysName = 0; | |
80 | Architecture = 0; | |
81 | memset(HashTable,0,sizeof(HashTable)); | |
82 | memset(Pools,0,sizeof(Pools)); | |
83 | } | |
84 | /*}}}*/ | |
85 | // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/ | |
86 | // --------------------------------------------------------------------- | |
87 | /* */ | |
88 | bool pkgCache::Header::CheckSizes(Header &Against) const | |
89 | { | |
90 | if (HeaderSz == Against.HeaderSz && | |
91 | PackageSz == Against.PackageSz && | |
92 | PackageFileSz == Against.PackageFileSz && | |
93 | VersionSz == Against.VersionSz && | |
94 | DescriptionSz == Against.DescriptionSz && | |
95 | DependencySz == Against.DependencySz && | |
96 | VerFileSz == Against.VerFileSz && | |
97 | DescFileSz == Against.DescFileSz && | |
98 | ProvidesSz == Against.ProvidesSz) | |
99 | return true; | |
100 | return false; | |
101 | } | |
102 | /*}}}*/ | |
103 | ||
104 | // Cache::pkgCache - Constructor /*{{{*/ | |
105 | // --------------------------------------------------------------------- | |
106 | /* */ | |
107 | pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map) | |
108 | { | |
109 | if (DoMap == true) | |
110 | ReMap(); | |
111 | } | |
112 | /*}}}*/ | |
113 | // Cache::ReMap - Reopen the cache file /*{{{*/ | |
114 | // --------------------------------------------------------------------- | |
115 | /* If the file is already closed then this will open it open it. */ | |
116 | bool pkgCache::ReMap() | |
117 | { | |
118 | // Apply the typecasts. | |
119 | HeaderP = (Header *)Map.Data(); | |
120 | PkgP = (Package *)Map.Data(); | |
121 | VerFileP = (VerFile *)Map.Data(); | |
122 | DescFileP = (DescFile *)Map.Data(); | |
123 | PkgFileP = (PackageFile *)Map.Data(); | |
124 | VerP = (Version *)Map.Data(); | |
125 | DescP = (Description *)Map.Data(); | |
126 | ProvideP = (Provides *)Map.Data(); | |
127 | TagP = (Tag *)Map.Data(); | |
128 | DepP = (Dependency *)Map.Data(); | |
129 | StringItemP = (StringItem *)Map.Data(); | |
130 | StrP = (char *)Map.Data(); | |
131 | ||
132 | if (Map.Size() == 0 || HeaderP == 0) | |
133 | return _error->Error(_("Empty package cache")); | |
134 | ||
135 | // Check the header | |
136 | Header DefHeader; | |
137 | if (HeaderP->Signature != DefHeader.Signature || | |
138 | HeaderP->Dirty == true) | |
139 | return _error->Error(_("The package cache file is corrupted")); | |
140 | ||
141 | if (HeaderP->MajorVersion != DefHeader.MajorVersion || | |
142 | HeaderP->MinorVersion != DefHeader.MinorVersion || | |
143 | HeaderP->CheckSizes(DefHeader) == false) | |
144 | return _error->Error(_("The package cache file is an incompatible version")); | |
145 | ||
146 | // Locate our VS.. | |
147 | if (HeaderP->VerSysName == 0 || | |
148 | (VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0) | |
149 | return _error->Error(_("This APT does not support the versioning system '%s'"),StrP + HeaderP->VerSysName); | |
150 | ||
151 | // Chcek the arhcitecture | |
152 | if (HeaderP->Architecture == 0 || | |
153 | _config->Find("APT::Architecture") != StrP + HeaderP->Architecture) | |
154 | return _error->Error(_("The package cache was built for a different architecture")); | |
155 | return true; | |
156 | } | |
157 | /*}}}*/ | |
158 | // Cache::Hash - Hash a string /*{{{*/ | |
159 | // --------------------------------------------------------------------- | |
160 | /* This is used to generate the hash entries for the HashTable. With my | |
161 | package list from bo this function gets 94% table usage on a 512 item | |
162 | table (480 used items) */ | |
163 | unsigned long pkgCache::sHash(const string &Str) const | |
164 | { | |
165 | unsigned long Hash = 0; | |
166 | for (string::const_iterator I = Str.begin(); I != Str.end(); I++) | |
167 | Hash = 5*Hash + tolower_ascii(*I); | |
168 | return Hash % _count(HeaderP->HashTable); | |
169 | } | |
170 | ||
171 | unsigned long pkgCache::sHash(const char *Str) const | |
172 | { | |
173 | unsigned long Hash = 0; | |
174 | for (const char *I = Str; *I != 0; I++) | |
175 | Hash = 5*Hash + tolower_ascii(*I); | |
176 | return Hash % _count(HeaderP->HashTable); | |
177 | } | |
178 | ||
179 | unsigned long pkgCache::sHash(const srkString &Str) const | |
180 | { | |
181 | unsigned long Hash = 0; | |
182 | for (const char *I = Str.Start, *E = I + Str.Size; I != E; I++) | |
183 | Hash = 5*Hash + tolower_ascii(*I); | |
184 | return Hash % _count(HeaderP->HashTable); | |
185 | } | |
186 | ||
187 | /*}}}*/ | |
188 | // Cache::FindPkg - Locate a package by name /*{{{*/ | |
189 | // --------------------------------------------------------------------- | |
190 | /* Returns 0 on error, pointer to the package otherwise */ | |
191 | pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) | |
192 | { | |
193 | return FindPkg(srkString(Name)); | |
194 | } | |
195 | ||
196 | pkgCache::PkgIterator pkgCache::FindPkg(const srkString &Name) | |
197 | { | |
198 | // Look at the hash bucket | |
199 | Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)]; | |
200 | for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage) | |
201 | { | |
202 | if (Pkg->Name != 0 && | |
203 | stringcasecmp(Name,StrP + Pkg->Name) == 0) | |
204 | return PkgIterator(*this,Pkg); | |
205 | } | |
206 | return PkgIterator(*this,0); | |
207 | } | |
208 | /*}}}*/ | |
209 | // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/ | |
210 | // --------------------------------------------------------------------- | |
211 | /* This returns a string representation of the dependency compare | |
212 | type in the weird debian style.. */ | |
213 | const char *pkgCache::CompTypeDeb(unsigned char Comp) | |
214 | { | |
215 | const char *Ops[] = {"","<=",">=","<<",">>","=","!="}; | |
216 | if ((unsigned)(Comp & 0xF) < 7) | |
217 | return Ops[Comp & 0xF]; | |
218 | return ""; | |
219 | } | |
220 | /*}}}*/ | |
221 | // Cache::CompType - Return a string describing the compare type /*{{{*/ | |
222 | // --------------------------------------------------------------------- | |
223 | /* This returns a string representation of the dependency compare | |
224 | type */ | |
225 | const char *pkgCache::CompType(unsigned char Comp) | |
226 | { | |
227 | const char *Ops[] = {"","<=",">=","<",">","=","!="}; | |
228 | if ((unsigned)(Comp & 0xF) < 7) | |
229 | return Ops[Comp & 0xF]; | |
230 | return ""; | |
231 | } | |
232 | /*}}}*/ | |
233 | // Cache::DepType - Return a string describing the dep type /*{{{*/ | |
234 | // --------------------------------------------------------------------- | |
235 | /* */ | |
236 | const char *pkgCache::DepType(unsigned char Type) | |
237 | { | |
238 | const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"), | |
239 | _("Recommends"),_("Conflicts"),_("Replaces"), | |
240 | _("Obsoletes"),_("Breaks"), _("Enhances")}; | |
241 | if (Type < sizeof(Types)/sizeof(*Types)) | |
242 | return Types[Type]; | |
243 | return ""; | |
244 | } | |
245 | /*}}}*/ | |
246 | // Cache::Priority - Convert a priority value to a string /*{{{*/ | |
247 | // --------------------------------------------------------------------- | |
248 | /* */ | |
249 | const char *pkgCache::Priority(unsigned char Prio) | |
250 | { | |
251 | const char *Mapping[] = {0,_("important"),_("required"),_("standard"), | |
252 | _("optional"),_("extra")}; | |
253 | if (Prio < _count(Mapping)) | |
254 | return Mapping[Prio]; | |
255 | return 0; | |
256 | } | |
257 | /*}}}*/ | |
258 | // Bases for iterator classes /*{{{*/ | |
259 | void pkgCache::VerIterator::_dummy() {} | |
260 | void pkgCache::DepIterator::_dummy() {} | |
261 | void pkgCache::PrvIterator::_dummy() {} | |
262 | void pkgCache::DescIterator::_dummy() {} | |
263 | /*}}}*/ | |
264 | // PkgIterator::operator ++ - Postfix incr /*{{{*/ | |
265 | // --------------------------------------------------------------------- | |
266 | /* This will advance to the next logical package in the hash table. */ | |
267 | void pkgCache::PkgIterator::operator ++(int) | |
268 | { | |
269 | // Follow the current links | |
270 | if (Pkg != Owner->PkgP) | |
271 | Pkg = Owner->PkgP + Pkg->NextPackage; | |
272 | ||
273 | // Follow the hash table | |
274 | while (Pkg == Owner->PkgP && (HashIndex+1) < (signed)_count(Owner->HeaderP->HashTable)) | |
275 | { | |
276 | HashIndex++; | |
277 | Pkg = Owner->PkgP + Owner->HeaderP->HashTable[HashIndex]; | |
278 | } | |
279 | }; | |
280 | /*}}}*/ | |
281 | // PkgIterator::State - Check the State of the package /*{{{*/ | |
282 | // --------------------------------------------------------------------- | |
283 | /* By this we mean if it is either cleanly installed or cleanly removed. */ | |
284 | pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const | |
285 | { | |
286 | if (Pkg->InstState == pkgCache::State::ReInstReq || | |
287 | Pkg->InstState == pkgCache::State::HoldReInstReq) | |
288 | return NeedsUnpack; | |
289 | ||
290 | if (Pkg->CurrentState == pkgCache::State::UnPacked || | |
291 | Pkg->CurrentState == pkgCache::State::HalfConfigured) | |
292 | // we leave triggers alone complettely. dpkg deals with | |
293 | // them in a hard-to-predict manner and if they get | |
294 | // resolved by dpkg before apt run dpkg --configure on | |
295 | // the TriggersPending package dpkg returns a error | |
296 | //Pkg->CurrentState == pkgCache::State::TriggersAwaited | |
297 | //Pkg->CurrentState == pkgCache::State::TriggersPending) | |
298 | return NeedsConfigure; | |
299 | ||
300 | if (Pkg->CurrentState == pkgCache::State::HalfInstalled || | |
301 | Pkg->InstState != pkgCache::State::Ok) | |
302 | return NeedsUnpack; | |
303 | ||
304 | return NeedsNothing; | |
305 | } | |
306 | /*}}}*/ | |
307 | // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/ | |
308 | // --------------------------------------------------------------------- | |
309 | /* Return string representing of the candidate version. */ | |
310 | const char * | |
311 | pkgCache::PkgIterator::CandVersion() const | |
312 | { | |
313 | //TargetVer is empty, so don't use it. | |
314 | VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this); | |
315 | if (version.IsGood()) | |
316 | return version.VerStr(); | |
317 | return 0; | |
318 | }; | |
319 | /*}}}*/ | |
320 | // PkgIterator::CurVersion - Returns the current version string /*{{{*/ | |
321 | // --------------------------------------------------------------------- | |
322 | /* Return string representing of the current version. */ | |
323 | const char * | |
324 | pkgCache::PkgIterator::CurVersion() const | |
325 | { | |
326 | VerIterator version = CurrentVer(); | |
327 | if (version.IsGood()) | |
328 | return CurrentVer().VerStr(); | |
329 | return 0; | |
330 | }; | |
331 | /*}}}*/ | |
332 | // ostream operator to handle string representation of a package /*{{{*/ | |
333 | // --------------------------------------------------------------------- | |
334 | /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section) | |
335 | Note that the characters <|>() are all literal above. Versions will be ommited | |
336 | if they provide no new information (e.g. there is no newer version than candidate) | |
337 | If no version and/or section can be found "none" is used. */ | |
338 | std::ostream& | |
339 | operator<<(ostream& out, pkgCache::PkgIterator Pkg) | |
340 | { | |
341 | if (Pkg.end() == true) | |
342 | return out << "invalid package"; | |
343 | ||
344 | string current = string(Pkg.CurVersion() == 0 ? "none" : Pkg.CurVersion()); | |
345 | string candidate = string(Pkg.CandVersion() == 0 ? "none" : Pkg.CandVersion()); | |
346 | string newest = string(Pkg.VersionList().end() ? "none" : Pkg.VersionList().VerStr()); | |
347 | ||
348 | out << Pkg.Name() << " < " << current; | |
349 | if (current != candidate) | |
350 | out << " -> " << candidate; | |
351 | if ( newest != "none" && candidate != newest) | |
352 | out << " | " << newest; | |
353 | out << " > ( " << string(Pkg.Section()==0?"none":Pkg.Section()) << " )"; | |
354 | return out; | |
355 | } | |
356 | /*}}}*/ | |
357 | // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/ | |
358 | // --------------------------------------------------------------------- | |
359 | /* Currently critical deps are defined as depends, predepends and | |
360 | conflicts (including dpkg's Breaks fields). */ | |
361 | bool pkgCache::DepIterator::IsCritical() | |
362 | { | |
363 | if (Dep->Type == pkgCache::Dep::Conflicts || | |
364 | Dep->Type == pkgCache::Dep::DpkgBreaks || | |
365 | Dep->Type == pkgCache::Dep::Obsoletes || | |
366 | Dep->Type == pkgCache::Dep::Depends || | |
367 | Dep->Type == pkgCache::Dep::PreDepends) | |
368 | return true; | |
369 | return false; | |
370 | } | |
371 | /*}}}*/ | |
372 | // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/ | |
373 | // --------------------------------------------------------------------- | |
374 | /* This intellegently looks at dep target packages and tries to figure | |
375 | out which package should be used. This is needed to nicely handle | |
376 | provide mapping. If the target package has no other providing packages | |
377 | then it returned. Otherwise the providing list is looked at to | |
378 | see if there is one one unique providing package if so it is returned. | |
379 | Otherwise true is returned and the target package is set. The return | |
380 | result indicates whether the node should be expandable | |
381 | ||
382 | In Conjunction with the DepCache the value of Result may not be | |
383 | super-good since the policy may have made it uninstallable. Using | |
384 | AllTargets is better in this case. */ | |
385 | bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) | |
386 | { | |
387 | Result = TargetPkg(); | |
388 | ||
389 | // No provides at all | |
390 | if (Result->ProvidesList == 0) | |
391 | return false; | |
392 | ||
393 | // There is the Base package and the providing ones which is at least 2 | |
394 | if (Result->VersionList != 0) | |
395 | return true; | |
396 | ||
397 | /* We have to skip over indirect provisions of the package that | |
398 | owns the dependency. For instance, if libc5-dev depends on the | |
399 | virtual package libc-dev which is provided by libc5-dev and libc6-dev | |
400 | we must ignore libc5-dev when considering the provides list. */ | |
401 | PrvIterator PStart = Result.ProvidesList(); | |
402 | for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); PStart++); | |
403 | ||
404 | // Nothing but indirect self provides | |
405 | if (PStart.end() == true) | |
406 | return false; | |
407 | ||
408 | // Check for single packages in the provides list | |
409 | PrvIterator P = PStart; | |
410 | for (; P.end() != true; P++) | |
411 | { | |
412 | // Skip over self provides | |
413 | if (P.OwnerPkg() == ParentPkg()) | |
414 | continue; | |
415 | if (PStart.OwnerPkg() != P.OwnerPkg()) | |
416 | break; | |
417 | } | |
418 | ||
419 | Result = PStart.OwnerPkg(); | |
420 | ||
421 | // Check for non dups | |
422 | if (P.end() != true) | |
423 | return true; | |
424 | ||
425 | return false; | |
426 | } | |
427 | /*}}}*/ | |
428 | // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/ | |
429 | // --------------------------------------------------------------------- | |
430 | /* This is a more useful version of TargetPkg() that follows versioned | |
431 | provides. It includes every possible package-version that could satisfy | |
432 | the dependency. The last item in the list has a 0. The resulting pointer | |
433 | must be delete [] 'd */ | |
434 | pkgCache::Version **pkgCache::DepIterator::AllTargets() | |
435 | { | |
436 | Version **Res = 0; | |
437 | unsigned long Size =0; | |
438 | while (1) | |
439 | { | |
440 | Version **End = Res; | |
441 | PkgIterator DPkg = TargetPkg(); | |
442 | ||
443 | // Walk along the actual package providing versions | |
444 | for (VerIterator I = DPkg.VersionList(); I.end() == false; I++) | |
445 | { | |
446 | if (Owner->VS->CheckDep(I.VerStr(),Dep->CompareOp,TargetVer()) == false) | |
447 | continue; | |
448 | ||
449 | if ((Dep->Type == pkgCache::Dep::Conflicts || | |
450 | Dep->Type == pkgCache::Dep::DpkgBreaks || | |
451 | Dep->Type == pkgCache::Dep::Obsoletes) && | |
452 | ParentPkg() == I.ParentPkg()) | |
453 | continue; | |
454 | ||
455 | Size++; | |
456 | if (Res != 0) | |
457 | *End++ = I; | |
458 | } | |
459 | ||
460 | // Follow all provides | |
461 | for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; I++) | |
462 | { | |
463 | if (Owner->VS->CheckDep(I.ProvideVersion(),Dep->CompareOp,TargetVer()) == false) | |
464 | continue; | |
465 | ||
466 | if ((Dep->Type == pkgCache::Dep::Conflicts || | |
467 | Dep->Type == pkgCache::Dep::DpkgBreaks || | |
468 | Dep->Type == pkgCache::Dep::Obsoletes) && | |
469 | ParentPkg() == I.OwnerPkg()) | |
470 | continue; | |
471 | ||
472 | Size++; | |
473 | if (Res != 0) | |
474 | *End++ = I.OwnerVer(); | |
475 | } | |
476 | ||
477 | // Do it again and write it into the array | |
478 | if (Res == 0) | |
479 | { | |
480 | Res = new Version *[Size+1]; | |
481 | Size = 0; | |
482 | } | |
483 | else | |
484 | { | |
485 | *End = 0; | |
486 | break; | |
487 | } | |
488 | } | |
489 | ||
490 | return Res; | |
491 | } | |
492 | /*}}}*/ | |
493 | // DepIterator::GlobOr - Compute an OR group /*{{{*/ | |
494 | // --------------------------------------------------------------------- | |
495 | /* This Takes an iterator, iterates past the current dependency grouping | |
496 | and returns Start and End so that so End is the final element | |
497 | in the group, if End == Start then D is End++ and End is the | |
498 | dependency D was pointing to. Use in loops to iterate sensibly. */ | |
499 | void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End) | |
500 | { | |
501 | // Compute a single dependency element (glob or) | |
502 | Start = *this; | |
503 | End = *this; | |
504 | for (bool LastOR = true; end() == false && LastOR == true;) | |
505 | { | |
506 | LastOR = (Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; | |
507 | (*this)++; | |
508 | if (LastOR == true) | |
509 | End = (*this); | |
510 | } | |
511 | } | |
512 | /*}}}*/ | |
513 | // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/ | |
514 | // --------------------------------------------------------------------- | |
515 | /* This just looks over the version list to see if B is listed before A. In | |
516 | most cases this will return in under 4 checks, ver lists are short. */ | |
517 | int pkgCache::VerIterator::CompareVer(const VerIterator &B) const | |
518 | { | |
519 | // Check if they are equal | |
520 | if (*this == B) | |
521 | return 0; | |
522 | if (end() == true) | |
523 | return -1; | |
524 | if (B.end() == true) | |
525 | return 1; | |
526 | ||
527 | /* Start at A and look for B. If B is found then A > B otherwise | |
528 | B was before A so A < B */ | |
529 | VerIterator I = *this; | |
530 | for (;I.end() == false; I++) | |
531 | if (I == B) | |
532 | return 1; | |
533 | return -1; | |
534 | } | |
535 | /*}}}*/ | |
536 | // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/ | |
537 | // --------------------------------------------------------------------- | |
538 | /* */ | |
539 | bool pkgCache::VerIterator::Downloadable() const | |
540 | { | |
541 | VerFileIterator Files = FileList(); | |
542 | for (; Files.end() == false; Files++) | |
543 | if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource) | |
544 | return true; | |
545 | return false; | |
546 | } | |
547 | /*}}}*/ | |
548 | // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/ | |
549 | // --------------------------------------------------------------------- | |
550 | /* This checks to see if any of the versions files are not NotAutomatic. | |
551 | True if this version is selectable for automatic installation. */ | |
552 | bool pkgCache::VerIterator::Automatic() const | |
553 | { | |
554 | VerFileIterator Files = FileList(); | |
555 | for (; Files.end() == false; Files++) | |
556 | if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic) | |
557 | return true; | |
558 | return false; | |
559 | } | |
560 | /*}}}*/ | |
561 | // VerIterator::NewestFile - Return the newest file version relation /*{{{*/ | |
562 | // --------------------------------------------------------------------- | |
563 | /* This looks at the version numbers associated with all of the sources | |
564 | this version is in and returns the highest.*/ | |
565 | pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const | |
566 | { | |
567 | VerFileIterator Files = FileList(); | |
568 | VerFileIterator Highest = Files; | |
569 | for (; Files.end() == false; Files++) | |
570 | { | |
571 | if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0) | |
572 | Highest = Files; | |
573 | } | |
574 | ||
575 | return Highest; | |
576 | } | |
577 | /*}}}*/ | |
578 | // VerIterator::RelStr - Release description string /*{{{*/ | |
579 | // --------------------------------------------------------------------- | |
580 | /* This describes the version from a release-centric manner. The output is a | |
581 | list of Label:Version/Archive */ | |
582 | string pkgCache::VerIterator::RelStr() | |
583 | { | |
584 | bool First = true; | |
585 | string Res; | |
586 | for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; I++) | |
587 | { | |
588 | // Do not print 'not source' entries' | |
589 | pkgCache::PkgFileIterator File = I.File(); | |
590 | if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource) | |
591 | continue; | |
592 | ||
593 | // See if we have already printed this out.. | |
594 | bool Seen = false; | |
595 | for (pkgCache::VerFileIterator J = this->FileList(); I != J; J++) | |
596 | { | |
597 | pkgCache::PkgFileIterator File2 = J.File(); | |
598 | if (File2->Label == 0 || File->Label == 0) | |
599 | continue; | |
600 | ||
601 | if (strcmp(File.Label(),File2.Label()) != 0) | |
602 | continue; | |
603 | ||
604 | if (File2->Version == File->Version) | |
605 | { | |
606 | Seen = true; | |
607 | break; | |
608 | } | |
609 | if (File2->Version == 0 || File->Version == 0) | |
610 | break; | |
611 | if (strcmp(File.Version(),File2.Version()) == 0) | |
612 | Seen = true; | |
613 | } | |
614 | ||
615 | if (Seen == true) | |
616 | continue; | |
617 | ||
618 | if (First == false) | |
619 | Res += ", "; | |
620 | else | |
621 | First = false; | |
622 | ||
623 | if (File->Label != 0) | |
624 | Res = Res + File.Label() + ':'; | |
625 | ||
626 | if (File->Archive != 0) | |
627 | { | |
628 | if (File->Version == 0) | |
629 | Res += File.Archive(); | |
630 | else | |
631 | Res = Res + File.Version() + '/' + File.Archive(); | |
632 | } | |
633 | else | |
634 | { | |
635 | // No release file, print the host name that this came from | |
636 | if (File->Site == 0 || File.Site()[0] == 0) | |
637 | Res += "localhost"; | |
638 | else | |
639 | Res += File.Site(); | |
640 | } | |
641 | } | |
642 | return Res; | |
643 | } | |
644 | /*}}}*/ | |
645 | // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/ | |
646 | // --------------------------------------------------------------------- | |
647 | /* This stats the file and compares its stats with the ones that were | |
648 | stored during generation. Date checks should probably also be | |
649 | included here. */ | |
650 | bool pkgCache::PkgFileIterator::IsOk() | |
651 | { | |
652 | struct stat Buf; | |
653 | if (stat(FileName(),&Buf) != 0) | |
654 | return false; | |
655 | ||
656 | if (Buf.st_size != (signed)File->Size || Buf.st_mtime != File->mtime) | |
657 | return false; | |
658 | ||
659 | return true; | |
660 | } | |
661 | /*}}}*/ | |
662 | // PkgFileIterator::RelStr - Return the release string /*{{{*/ | |
663 | // --------------------------------------------------------------------- | |
664 | /* */ | |
665 | string pkgCache::PkgFileIterator::RelStr() | |
666 | { | |
667 | string Res; | |
668 | if (Version() != 0) | |
669 | Res = Res + (Res.empty() == true?"v=":",v=") + Version(); | |
670 | if (Origin() != 0) | |
671 | Res = Res + (Res.empty() == true?"o=":",o=") + Origin(); | |
672 | if (Archive() != 0) | |
673 | Res = Res + (Res.empty() == true?"a=":",a=") + Archive(); | |
674 | if (Label() != 0) | |
675 | Res = Res + (Res.empty() == true?"l=":",l=") + Label(); | |
676 | if (Component() != 0) | |
677 | Res = Res + (Res.empty() == true?"c=":",c=") + Component(); | |
678 | return Res; | |
679 | } | |
680 | /*}}}*/ | |
681 | // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/ | |
682 | // --------------------------------------------------------------------- | |
683 | /* return a DescIter for the current locale or the default if none is | |
684 | * found | |
685 | */ | |
686 | pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const | |
687 | { | |
688 | pkgCache::DescIterator DescDefault = DescriptionList(); | |
689 | pkgCache::DescIterator Desc = DescDefault; | |
690 | for (; Desc.end() == false; Desc++) | |
691 | if (pkgIndexFile::LanguageCode() == Desc.LanguageCode()) | |
692 | break; | |
693 | if (Desc.end() == true) | |
694 | Desc = DescDefault; | |
695 | return Desc; | |
696 | }; | |
697 | ||
698 | /*}}}*/ |