]>
git.saurik.com Git - apt.git/blob - apt-pkg/pkgcache.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.cc,v 1.37 2003/02/10 01:40:58 doogie Exp $
4 /* ######################################################################
6 Package Cache - Accessor code for the cache
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!!
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.
17 The main class provides for ways to get package indexes and some
18 general lookup functions to start the iterators.
20 ##################################################################### */
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 #include <apt-pkg/macros.h>
44 // Cache::Header::Header - Constructor /*{{{*/
45 // ---------------------------------------------------------------------
46 /* Simply initialize the header */
47 pkgCache::Header::Header()
49 Signature
= 0x98FE76DC;
51 /* Whenever the structures change the major version should be bumped,
52 whenever the generator changes the minor version should be bumped. */
57 HeaderSz
= sizeof(pkgCache::Header
);
58 GroupSz
= sizeof(pkgCache::Group
);
59 PackageSz
= sizeof(pkgCache::Package
);
60 PackageFileSz
= sizeof(pkgCache::PackageFile
);
61 VersionSz
= sizeof(pkgCache::Version
);
62 DescriptionSz
= sizeof(pkgCache::Description
);
63 DependencySz
= sizeof(pkgCache::Dependency
);
64 ProvidesSz
= sizeof(pkgCache::Provides
);
65 VerFileSz
= sizeof(pkgCache::VerFile
);
66 DescFileSz
= sizeof(pkgCache::DescFile
);
84 memset(PkgHashTable
,0,sizeof(PkgHashTable
));
85 memset(GrpHashTable
,0,sizeof(GrpHashTable
));
86 memset(Pools
,0,sizeof(Pools
));
91 // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/
92 // ---------------------------------------------------------------------
94 bool pkgCache::Header::CheckSizes(Header
&Against
) const
96 if (HeaderSz
== Against
.HeaderSz
&&
97 GroupSz
== Against
.GroupSz
&&
98 PackageSz
== Against
.PackageSz
&&
99 PackageFileSz
== Against
.PackageFileSz
&&
100 VersionSz
== Against
.VersionSz
&&
101 DescriptionSz
== Against
.DescriptionSz
&&
102 DependencySz
== Against
.DependencySz
&&
103 VerFileSz
== Against
.VerFileSz
&&
104 DescFileSz
== Against
.DescFileSz
&&
105 ProvidesSz
== Against
.ProvidesSz
)
111 // Cache::pkgCache - Constructor /*{{{*/
112 // ---------------------------------------------------------------------
114 pkgCache::pkgCache(MMap
*Map
, bool DoMap
) : Map(*Map
)
116 // call getArchitectures() with cached=false to ensure that the
117 // architectures cache is re-evaulated. this is needed in cases
118 // when the APT::Architecture field changes between two cache creations
119 MultiArchEnabled
= APT::Configuration::getArchitectures(false).size() > 1;
124 // Cache::ReMap - Reopen the cache file /*{{{*/
125 // ---------------------------------------------------------------------
126 /* If the file is already closed then this will open it open it. */
127 bool pkgCache::ReMap(bool const &Errorchecks
)
129 // Apply the typecasts.
130 HeaderP
= (Header
*)Map
.Data();
131 GrpP
= (Group
*)Map
.Data();
132 PkgP
= (Package
*)Map
.Data();
133 VerFileP
= (VerFile
*)Map
.Data();
134 DescFileP
= (DescFile
*)Map
.Data();
135 PkgFileP
= (PackageFile
*)Map
.Data();
136 VerP
= (Version
*)Map
.Data();
137 DescP
= (Description
*)Map
.Data();
138 ProvideP
= (Provides
*)Map
.Data();
139 DepP
= (Dependency
*)Map
.Data();
140 StringItemP
= (StringItem
*)Map
.Data();
141 StrP
= (char *)Map
.Data();
143 if (Errorchecks
== false)
146 if (Map
.Size() == 0 || HeaderP
== 0)
147 return _error
->Error(_("Empty package cache"));
151 if (HeaderP
->Signature
!= DefHeader
.Signature
||
152 HeaderP
->Dirty
== true)
153 return _error
->Error(_("The package cache file is corrupted"));
155 if (HeaderP
->MajorVersion
!= DefHeader
.MajorVersion
||
156 HeaderP
->MinorVersion
!= DefHeader
.MinorVersion
||
157 HeaderP
->CheckSizes(DefHeader
) == false)
158 return _error
->Error(_("The package cache file is an incompatible version"));
160 if (Map
.Size() < HeaderP
->CacheFileSize
)
161 return _error
->Error(_("The package cache file is corrupted, it is too small"));
164 if (HeaderP
->VerSysName
== 0 ||
165 (VS
= pkgVersioningSystem::GetVS(StrP
+ HeaderP
->VerSysName
)) == 0)
166 return _error
->Error(_("This APT does not support the versioning system '%s'"),StrP
+ HeaderP
->VerSysName
);
168 // Chcek the arhcitecture
169 if (HeaderP
->Architecture
== 0 ||
170 _config
->Find("APT::Architecture") != StrP
+ HeaderP
->Architecture
)
171 return _error
->Error(_("The package cache was built for a different architecture"));
175 // Cache::Hash - Hash a string /*{{{*/
176 // ---------------------------------------------------------------------
177 /* This is used to generate the hash entries for the HashTable. With my
178 package list from bo this function gets 94% table usage on a 512 item
179 table (480 used items) */
180 unsigned long pkgCache::sHash(const string
&Str
) const
182 unsigned long Hash
= 0;
183 for (string::const_iterator I
= Str
.begin(); I
!= Str
.end(); I
++)
184 Hash
= 5*Hash
+ tolower_ascii(*I
);
185 return Hash
% _count(HeaderP
->PkgHashTable
);
188 unsigned long pkgCache::sHash(const char *Str
) const
190 unsigned long Hash
= 0;
191 for (const char *I
= Str
; *I
!= 0; I
++)
192 Hash
= 5*Hash
+ tolower_ascii(*I
);
193 return Hash
% _count(HeaderP
->PkgHashTable
);
197 // Cache::SingleArchFindPkg - Locate a package by name /*{{{*/
198 // ---------------------------------------------------------------------
199 /* Returns 0 on error, pointer to the package otherwise
200 The multiArch enabled methods will fallback to this one as it is (a bit)
201 faster for single arch environments and realworld is mostly singlearch… */
202 pkgCache::PkgIterator
pkgCache::SingleArchFindPkg(const string
&Name
)
204 // Look at the hash bucket
205 Package
*Pkg
= PkgP
+ HeaderP
->PkgHashTable
[Hash(Name
)];
206 for (; Pkg
!= PkgP
; Pkg
= PkgP
+ Pkg
->NextPackage
)
208 if (Pkg
->Name
!= 0 && StrP
[Pkg
->Name
] == Name
[0] &&
209 stringcasecmp(Name
,StrP
+ Pkg
->Name
) == 0)
210 return PkgIterator(*this,Pkg
);
212 return PkgIterator(*this,0);
215 // Cache::FindPkg - Locate a package by name /*{{{*/
216 // ---------------------------------------------------------------------
217 /* Returns 0 on error, pointer to the package otherwise */
218 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
) {
219 size_t const found
= Name
.find(':');
220 if (found
== string::npos
)
222 if (MultiArchCache() == false)
223 return SingleArchFindPkg(Name
);
225 return FindPkg(Name
, "native");
227 string
const Arch
= Name
.substr(found
+1);
228 /* Beware: This is specialcased to handle pkg:any in dependencies as
229 these are linked to virtual pkg:any named packages with all archs.
230 If you want any arch from a given pkg, use FindPkg(pkg,arch) */
232 return FindPkg(Name
, "any");
233 return FindPkg(Name
.substr(0, found
), Arch
);
236 // Cache::FindPkg - Locate a package by name /*{{{*/
237 // ---------------------------------------------------------------------
238 /* Returns 0 on error, pointer to the package otherwise */
239 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
, string
const &Arch
) {
240 if (MultiArchCache() == false) {
241 if (Arch
== "native" || Arch
== "all" || Arch
== "any" ||
242 Arch
== NativeArch())
243 return SingleArchFindPkg(Name
);
245 return PkgIterator(*this,0);
247 /* We make a detour via the GrpIterator here as
248 on a multi-arch environment a group is easier to
249 find than a package (less entries in the buckets) */
250 pkgCache::GrpIterator Grp
= FindGrp(Name
);
251 if (Grp
.end() == true)
252 return PkgIterator(*this,0);
254 return Grp
.FindPkg(Arch
);
257 // Cache::FindGrp - Locate a group by name /*{{{*/
258 // ---------------------------------------------------------------------
259 /* Returns End-Pointer on error, pointer to the group otherwise */
260 pkgCache::GrpIterator
pkgCache::FindGrp(const string
&Name
) {
261 if (unlikely(Name
.empty() == true))
262 return GrpIterator(*this,0);
264 // Look at the hash bucket for the group
265 Group
*Grp
= GrpP
+ HeaderP
->GrpHashTable
[sHash(Name
)];
266 for (; Grp
!= GrpP
; Grp
= GrpP
+ Grp
->Next
) {
267 if (Grp
->Name
!= 0 && StrP
[Grp
->Name
] == Name
[0] &&
268 stringcasecmp(Name
, StrP
+ Grp
->Name
) == 0)
269 return GrpIterator(*this, Grp
);
272 return GrpIterator(*this,0);
275 // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
276 // ---------------------------------------------------------------------
277 /* This returns a string representation of the dependency compare
278 type in the weird debian style.. */
279 const char *pkgCache::CompTypeDeb(unsigned char Comp
)
281 const char *Ops
[] = {"","<=",">=","<<",">>","=","!="};
282 if ((unsigned)(Comp
& 0xF) < 7)
283 return Ops
[Comp
& 0xF];
287 // Cache::CompType - Return a string describing the compare type /*{{{*/
288 // ---------------------------------------------------------------------
289 /* This returns a string representation of the dependency compare
291 const char *pkgCache::CompType(unsigned char Comp
)
293 const char *Ops
[] = {"","<=",">=","<",">","=","!="};
294 if ((unsigned)(Comp
& 0xF) < 7)
295 return Ops
[Comp
& 0xF];
299 // Cache::DepType - Return a string describing the dep type /*{{{*/
300 // ---------------------------------------------------------------------
302 const char *pkgCache::DepType(unsigned char Type
)
304 const char *Types
[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
305 _("Recommends"),_("Conflicts"),_("Replaces"),
306 _("Obsoletes"),_("Breaks"), _("Enhances")};
307 if (Type
< sizeof(Types
)/sizeof(*Types
))
312 // Cache::Priority - Convert a priority value to a string /*{{{*/
313 // ---------------------------------------------------------------------
315 const char *pkgCache::Priority(unsigned char Prio
)
317 const char *Mapping
[] = {0,_("important"),_("required"),_("standard"),
318 _("optional"),_("extra")};
319 if (Prio
< _count(Mapping
))
320 return Mapping
[Prio
];
324 // GrpIterator::FindPkg - Locate a package by arch /*{{{*/
325 // ---------------------------------------------------------------------
326 /* Returns an End-Pointer on error, pointer to the package otherwise */
327 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPkg(string Arch
) const {
328 if (unlikely(IsGood() == false || S
->FirstPackage
== 0))
329 return PkgIterator(*Owner
, 0);
331 /* If we accept any package we simply return the "first"
332 package in this group (the last one added). */
334 return PkgIterator(*Owner
, Owner
->PkgP
+ S
->FirstPackage
);
336 char const* const myArch
= Owner
->NativeArch();
337 /* Most of the time the package for our native architecture is
338 the one we add at first to the cache, but this would be the
339 last one we check, so we do it now. */
340 if (Arch
== "native" || Arch
== myArch
|| Arch
== "all") {
341 pkgCache::Package
*Pkg
= Owner
->PkgP
+ S
->LastPackage
;
342 if (strcasecmp(myArch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
343 return PkgIterator(*Owner
, Pkg
);
347 /* Iterate over the list to find the matching arch
348 unfortunately this list includes "package noise"
349 (= different packages with same calculated hash),
350 so we need to check the name also */
351 for (pkgCache::Package
*Pkg
= PackageList(); Pkg
!= Owner
->PkgP
;
352 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
353 if (S
->Name
== Pkg
->Name
&&
354 stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
355 return PkgIterator(*Owner
, Pkg
);
356 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
360 return PkgIterator(*Owner
, 0);
363 // GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/
364 // ---------------------------------------------------------------------
365 /* Returns an End-Pointer on error, pointer to the package otherwise */
366 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual
) const {
367 pkgCache::PkgIterator Pkg
= FindPkg("native");
368 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
371 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
372 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
373 a
!= archs
.end(); ++a
) {
375 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
379 if (PreferNonVirtual
== true)
380 return FindPreferredPkg(false);
381 return PkgIterator(*Owner
, 0);
384 // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
385 // ---------------------------------------------------------------------
386 /* Returns an End-Pointer on error, pointer to the package otherwise.
387 We can't simply ++ to the next as the next package of the last will
388 be from a different group (with the same hash value) */
389 pkgCache::PkgIterator
pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator
const &LastPkg
) const {
390 if (unlikely(IsGood() == false || S
->FirstPackage
== 0 ||
391 LastPkg
.end() == true))
392 return PkgIterator(*Owner
, 0);
394 if (S
->LastPackage
== LastPkg
.Index())
395 return PkgIterator(*Owner
, 0);
397 return PkgIterator(*Owner
, Owner
->PkgP
+ LastPkg
->NextPackage
);
400 // GrpIterator::operator ++ - Postfix incr /*{{{*/
401 // ---------------------------------------------------------------------
402 /* This will advance to the next logical group in the hash table. */
403 void pkgCache::GrpIterator::operator ++(int)
405 // Follow the current links
406 if (S
!= Owner
->GrpP
)
407 S
= Owner
->GrpP
+ S
->Next
;
409 // Follow the hash table
410 while (S
== Owner
->GrpP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->GrpHashTable
))
413 S
= Owner
->GrpP
+ Owner
->HeaderP
->GrpHashTable
[HashIndex
];
417 // PkgIterator::operator ++ - Postfix incr /*{{{*/
418 // ---------------------------------------------------------------------
419 /* This will advance to the next logical package in the hash table. */
420 void pkgCache::PkgIterator::operator ++(int)
422 // Follow the current links
423 if (S
!= Owner
->PkgP
)
424 S
= Owner
->PkgP
+ S
->NextPackage
;
426 // Follow the hash table
427 while (S
== Owner
->PkgP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->PkgHashTable
))
430 S
= Owner
->PkgP
+ Owner
->HeaderP
->PkgHashTable
[HashIndex
];
434 // PkgIterator::State - Check the State of the package /*{{{*/
435 // ---------------------------------------------------------------------
436 /* By this we mean if it is either cleanly installed or cleanly removed. */
437 pkgCache::PkgIterator::OkState
pkgCache::PkgIterator::State() const
439 if (S
->InstState
== pkgCache::State::ReInstReq
||
440 S
->InstState
== pkgCache::State::HoldReInstReq
)
443 if (S
->CurrentState
== pkgCache::State::UnPacked
||
444 S
->CurrentState
== pkgCache::State::HalfConfigured
)
445 // we leave triggers alone complettely. dpkg deals with
446 // them in a hard-to-predict manner and if they get
447 // resolved by dpkg before apt run dpkg --configure on
448 // the TriggersPending package dpkg returns a error
449 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
450 //Pkg->CurrentState == pkgCache::State::TriggersPending)
451 return NeedsConfigure
;
453 if (S
->CurrentState
== pkgCache::State::HalfInstalled
||
454 S
->InstState
!= pkgCache::State::Ok
)
460 // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
461 // ---------------------------------------------------------------------
462 /* Return string representing of the candidate version. */
464 pkgCache::PkgIterator::CandVersion() const
466 //TargetVer is empty, so don't use it.
467 VerIterator version
= pkgPolicy(Owner
).GetCandidateVer(*this);
468 if (version
.IsGood())
469 return version
.VerStr();
473 // PkgIterator::CurVersion - Returns the current version string /*{{{*/
474 // ---------------------------------------------------------------------
475 /* Return string representing of the current version. */
477 pkgCache::PkgIterator::CurVersion() const
479 VerIterator version
= CurrentVer();
480 if (version
.IsGood())
481 return CurrentVer().VerStr();
485 // ostream operator to handle string representation of a package /*{{{*/
486 // ---------------------------------------------------------------------
487 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
488 Note that the characters <|>() are all literal above. Versions will be ommited
489 if they provide no new information (e.g. there is no newer version than candidate)
490 If no version and/or section can be found "none" is used. */
492 operator<<(ostream
& out
, pkgCache::PkgIterator Pkg
)
494 if (Pkg
.end() == true)
495 return out
<< "invalid package";
497 string current
= string(Pkg
.CurVersion() == 0 ? "none" : Pkg
.CurVersion());
498 string candidate
= string(Pkg
.CandVersion() == 0 ? "none" : Pkg
.CandVersion());
499 string newest
= string(Pkg
.VersionList().end() ? "none" : Pkg
.VersionList().VerStr());
501 out
<< Pkg
.Name() << " [ " << Pkg
.Arch() << " ] < " << current
;
502 if (current
!= candidate
)
503 out
<< " -> " << candidate
;
504 if ( newest
!= "none" && candidate
!= newest
)
505 out
<< " | " << newest
;
506 out
<< " > ( " << string(Pkg
.Section()==0?"none":Pkg
.Section()) << " )";
510 // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/
511 // ---------------------------------------------------------------------
512 /* Returns a name:arch string */
513 std::string
pkgCache::PkgIterator::FullName(bool const &Pretty
) const
515 string fullname
= Name();
516 if (Pretty
== false ||
517 (strcmp(Arch(), "all") != 0 &&
518 strcmp(Owner
->NativeArch(), Arch()) != 0))
519 return fullname
.append(":").append(Arch());
523 // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
524 // ---------------------------------------------------------------------
525 /* Currently critical deps are defined as depends, predepends and
526 conflicts (including dpkg's Breaks fields). */
527 bool pkgCache::DepIterator::IsCritical() const
529 if (IsNegative() == true ||
530 S
->Type
== pkgCache::Dep::Depends
||
531 S
->Type
== pkgCache::Dep::PreDepends
)
536 // DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/
537 // ---------------------------------------------------------------------
538 /* Some dependencies are positive like Depends and Recommends, others
539 are negative like Conflicts which can and should be handled differently */
540 bool pkgCache::DepIterator::IsNegative() const
542 return S
->Type
== Dep::DpkgBreaks
||
543 S
->Type
== Dep::Conflicts
||
544 S
->Type
== Dep::Obsoletes
;
547 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
548 // ---------------------------------------------------------------------
549 /* This intellegently looks at dep target packages and tries to figure
550 out which package should be used. This is needed to nicely handle
551 provide mapping. If the target package has no other providing packages
552 then it returned. Otherwise the providing list is looked at to
553 see if there is one one unique providing package if so it is returned.
554 Otherwise true is returned and the target package is set. The return
555 result indicates whether the node should be expandable
557 In Conjunction with the DepCache the value of Result may not be
558 super-good since the policy may have made it uninstallable. Using
559 AllTargets is better in this case. */
560 bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator
&Result
) const
562 Result
= TargetPkg();
564 // No provides at all
565 if (Result
->ProvidesList
== 0)
568 // There is the Base package and the providing ones which is at least 2
569 if (Result
->VersionList
!= 0)
572 /* We have to skip over indirect provisions of the package that
573 owns the dependency. For instance, if libc5-dev depends on the
574 virtual package libc-dev which is provided by libc5-dev and libc6-dev
575 we must ignore libc5-dev when considering the provides list. */
576 PrvIterator PStart
= Result
.ProvidesList();
577 for (; PStart
.end() != true && PStart
.OwnerPkg() == ParentPkg(); PStart
++);
579 // Nothing but indirect self provides
580 if (PStart
.end() == true)
583 // Check for single packages in the provides list
584 PrvIterator P
= PStart
;
585 for (; P
.end() != true; P
++)
587 // Skip over self provides
588 if (P
.OwnerPkg() == ParentPkg())
590 if (PStart
.OwnerPkg() != P
.OwnerPkg())
594 Result
= PStart
.OwnerPkg();
596 // Check for non dups
603 // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
604 // ---------------------------------------------------------------------
605 /* This is a more useful version of TargetPkg() that follows versioned
606 provides. It includes every possible package-version that could satisfy
607 the dependency. The last item in the list has a 0. The resulting pointer
608 must be delete [] 'd */
609 pkgCache::Version
**pkgCache::DepIterator::AllTargets() const
612 unsigned long Size
=0;
616 PkgIterator DPkg
= TargetPkg();
618 // Walk along the actual package providing versions
619 for (VerIterator I
= DPkg
.VersionList(); I
.end() == false; I
++)
621 if (Owner
->VS
->CheckDep(I
.VerStr(),S
->CompareOp
,TargetVer()) == false)
624 if (IsNegative() == true &&
625 ParentPkg() == I
.ParentPkg())
633 // Follow all provides
634 for (PrvIterator I
= DPkg
.ProvidesList(); I
.end() == false; I
++)
636 if (Owner
->VS
->CheckDep(I
.ProvideVersion(),S
->CompareOp
,TargetVer()) == false)
639 if (IsNegative() == true &&
640 ParentPkg() == I
.OwnerPkg())
645 *End
++ = I
.OwnerVer();
648 // Do it again and write it into the array
651 Res
= new Version
*[Size
+1];
664 // DepIterator::GlobOr - Compute an OR group /*{{{*/
665 // ---------------------------------------------------------------------
666 /* This Takes an iterator, iterates past the current dependency grouping
667 and returns Start and End so that so End is the final element
668 in the group, if End == Start then D is End++ and End is the
669 dependency D was pointing to. Use in loops to iterate sensibly. */
670 void pkgCache::DepIterator::GlobOr(DepIterator
&Start
,DepIterator
&End
)
672 // Compute a single dependency element (glob or)
675 for (bool LastOR
= true; end() == false && LastOR
== true;)
677 LastOR
= (S
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
684 // ostream operator to handle string representation of a dependecy /*{{{*/
685 // ---------------------------------------------------------------------
687 std::ostream
& operator<<(ostream
& out
, pkgCache::DepIterator D
)
690 return out
<< "invalid dependency";
692 pkgCache::PkgIterator P
= D
.ParentPkg();
693 pkgCache::PkgIterator T
= D
.TargetPkg();
695 out
<< (P
.end() ? "invalid pkg" : P
.FullName(false)) << " " << D
.DepType()
698 out
<< "invalid pkg";
703 out
<< " (" << D
.CompType() << " " << D
.TargetVer() << ")";
708 // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
709 // ---------------------------------------------------------------------
710 /* This just looks over the version list to see if B is listed before A. In
711 most cases this will return in under 4 checks, ver lists are short. */
712 int pkgCache::VerIterator::CompareVer(const VerIterator
&B
) const
714 // Check if they are equal
722 /* Start at A and look for B. If B is found then A > B otherwise
723 B was before A so A < B */
724 VerIterator I
= *this;
725 for (;I
.end() == false; I
++)
731 // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
732 // ---------------------------------------------------------------------
734 bool pkgCache::VerIterator::Downloadable() const
736 VerFileIterator Files
= FileList();
737 for (; Files
.end() == false; Files
++)
738 if ((Files
.File()->Flags
& pkgCache::Flag::NotSource
) != pkgCache::Flag::NotSource
)
743 // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
744 // ---------------------------------------------------------------------
745 /* This checks to see if any of the versions files are not NotAutomatic.
746 True if this version is selectable for automatic installation. */
747 bool pkgCache::VerIterator::Automatic() const
749 VerFileIterator Files
= FileList();
750 for (; Files
.end() == false; Files
++)
751 // Do not check ButAutomaticUpgrades here as it is kind of automatic…
752 if ((Files
.File()->Flags
& pkgCache::Flag::NotAutomatic
) != pkgCache::Flag::NotAutomatic
)
757 // VerIterator::NewestFile - Return the newest file version relation /*{{{*/
758 // ---------------------------------------------------------------------
759 /* This looks at the version numbers associated with all of the sources
760 this version is in and returns the highest.*/
761 pkgCache::VerFileIterator
pkgCache::VerIterator::NewestFile() const
763 VerFileIterator Files
= FileList();
764 VerFileIterator Highest
= Files
;
765 for (; Files
.end() == false; Files
++)
767 if (Owner
->VS
->CmpReleaseVer(Files
.File().Version(),Highest
.File().Version()) > 0)
774 // VerIterator::RelStr - Release description string /*{{{*/
775 // ---------------------------------------------------------------------
776 /* This describes the version from a release-centric manner. The output is a
777 list of Label:Version/Archive */
778 string
pkgCache::VerIterator::RelStr() const
782 for (pkgCache::VerFileIterator I
= this->FileList(); I
.end() == false; I
++)
784 // Do not print 'not source' entries'
785 pkgCache::PkgFileIterator File
= I
.File();
786 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
789 // See if we have already printed this out..
791 for (pkgCache::VerFileIterator J
= this->FileList(); I
!= J
; J
++)
793 pkgCache::PkgFileIterator File2
= J
.File();
794 if (File2
->Label
== 0 || File
->Label
== 0)
797 if (strcmp(File
.Label(),File2
.Label()) != 0)
800 if (File2
->Version
== File
->Version
)
805 if (File2
->Version
== 0 || File
->Version
== 0)
807 if (strcmp(File
.Version(),File2
.Version()) == 0)
819 if (File
->Label
!= 0)
820 Res
= Res
+ File
.Label() + ':';
822 if (File
->Archive
!= 0)
824 if (File
->Version
== 0)
825 Res
+= File
.Archive();
827 Res
= Res
+ File
.Version() + '/' + File
.Archive();
831 // No release file, print the host name that this came from
832 if (File
->Site
== 0 || File
.Site()[0] == 0)
838 if (S
->ParentPkg
!= 0)
839 Res
.append(" [").append(Arch()).append("]");
843 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
844 // ---------------------------------------------------------------------
845 /* This stats the file and compares its stats with the ones that were
846 stored during generation. Date checks should probably also be
848 bool pkgCache::PkgFileIterator::IsOk()
851 if (stat(FileName(),&Buf
) != 0)
854 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
860 // PkgFileIterator::RelStr - Return the release string /*{{{*/
861 // ---------------------------------------------------------------------
863 string
pkgCache::PkgFileIterator::RelStr()
867 Res
= Res
+ (Res
.empty() == true?"v=":",v=") + Version();
869 Res
= Res
+ (Res
.empty() == true?"o=":",o=") + Origin();
871 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Archive();
873 Res
= Res
+ (Res
.empty() == true?"n=":",n=") + Codename();
875 Res
= Res
+ (Res
.empty() == true?"l=":",l=") + Label();
876 if (Component() != 0)
877 Res
= Res
+ (Res
.empty() == true?"c=":",c=") + Component();
878 if (Architecture() != 0)
879 Res
= Res
+ (Res
.empty() == true?"b=":",b=") + Architecture();
883 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
884 // ---------------------------------------------------------------------
885 /* return a DescIter for the current locale or the default if none is
888 pkgCache::DescIterator
pkgCache::VerIterator::TranslatedDescription() const
890 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
891 for (std::vector
<string
>::const_iterator l
= lang
.begin();
892 l
!= lang
.end(); l
++)
894 pkgCache::DescIterator Desc
= DescriptionList();
895 for (; Desc
.end() == false; ++Desc
)
896 if (*l
== Desc
.LanguageCode() ||
897 (*l
== "en" && strcmp(Desc
.LanguageCode(),"") == 0))
899 if (Desc
.end() == true)
903 for (pkgCache::DescIterator Desc
= DescriptionList();
904 Desc
.end() == false; ++Desc
)
905 if (strcmp(Desc
.LanguageCode(), "") == 0)
907 return DescriptionList();