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