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 management. 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 /*{{{*/
25 #include <apt-pkg/pkgcache.h>
26 #include <apt-pkg/policy.h>
27 #include <apt-pkg/version.h>
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/strutl.h>
30 #include <apt-pkg/configuration.h>
31 #include <apt-pkg/aptconfiguration.h>
32 #include <apt-pkg/mmap.h>
33 #include <apt-pkg/macros.h>
48 // Cache::Header::Header - Constructor /*{{{*/
49 // ---------------------------------------------------------------------
50 /* Simply initialize the header */
51 pkgCache::Header::Header()
53 Signature
= 0x98FE76DC;
55 /* Whenever the structures change the major version should be bumped,
56 whenever the generator changes the minor version should be bumped. */
61 HeaderSz
= sizeof(pkgCache::Header
);
62 GroupSz
= sizeof(pkgCache::Group
);
63 PackageSz
= sizeof(pkgCache::Package
);
64 ReleaseFileSz
= sizeof(pkgCache::ReleaseFile
);
65 PackageFileSz
= sizeof(pkgCache::PackageFile
);
66 VersionSz
= sizeof(pkgCache::Version
);
67 DescriptionSz
= sizeof(pkgCache::Description
);
68 DependencySz
= sizeof(pkgCache::Dependency
);
69 DependencyDataSz
= sizeof(pkgCache::DependencyData
);
70 ProvidesSz
= sizeof(pkgCache::Provides
);
71 VerFileSz
= sizeof(pkgCache::VerFile
);
72 DescFileSz
= sizeof(pkgCache::DescFile
);
93 SetHashTableSize(_config
->FindI("APT::Cache-HashTableSize", 10 * 1048));
94 memset(Pools
,0,sizeof(Pools
));
99 // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/
100 // ---------------------------------------------------------------------
102 bool pkgCache::Header::CheckSizes(Header
&Against
) const
104 if (HeaderSz
== Against
.HeaderSz
&&
105 GroupSz
== Against
.GroupSz
&&
106 PackageSz
== Against
.PackageSz
&&
107 ReleaseFileSz
== Against
.ReleaseFileSz
&&
108 PackageFileSz
== Against
.PackageFileSz
&&
109 VersionSz
== Against
.VersionSz
&&
110 DescriptionSz
== Against
.DescriptionSz
&&
111 DependencySz
== Against
.DependencySz
&&
112 DependencyDataSz
== Against
.DependencyDataSz
&&
113 VerFileSz
== Against
.VerFileSz
&&
114 DescFileSz
== Against
.DescFileSz
&&
115 ProvidesSz
== Against
.ProvidesSz
)
121 // Cache::pkgCache - Constructor /*{{{*/
122 // ---------------------------------------------------------------------
124 APT_IGNORE_DEPRECATED_PUSH
125 pkgCache::pkgCache(MMap
*Map
, bool DoMap
) : Map(*Map
), d(NULL
)
127 // call getArchitectures() with cached=false to ensure that the
128 // architectures cache is re-evaulated. this is needed in cases
129 // when the APT::Architecture field changes between two cache creations
130 MultiArchEnabled
= APT::Configuration::getArchitectures(false).size() > 1;
134 APT_IGNORE_DEPRECATED_POP
136 // Cache::ReMap - Reopen the cache file /*{{{*/
137 // ---------------------------------------------------------------------
138 /* If the file is already closed then this will open it open it. */
139 bool pkgCache::ReMap(bool const &Errorchecks
)
141 // Apply the typecasts.
142 HeaderP
= (Header
*)Map
.Data();
143 GrpP
= (Group
*)Map
.Data();
144 PkgP
= (Package
*)Map
.Data();
145 VerFileP
= (VerFile
*)Map
.Data();
146 DescFileP
= (DescFile
*)Map
.Data();
147 RlsFileP
= (ReleaseFile
*)Map
.Data();
148 PkgFileP
= (PackageFile
*)Map
.Data();
149 VerP
= (Version
*)Map
.Data();
150 DescP
= (Description
*)Map
.Data();
151 ProvideP
= (Provides
*)Map
.Data();
152 DepP
= (Dependency
*)Map
.Data();
153 DepDataP
= (DependencyData
*)Map
.Data();
154 StrP
= (char *)Map
.Data();
156 if (Errorchecks
== false)
159 if (Map
.Size() == 0 || HeaderP
== 0)
160 return _error
->Error(_("Empty package cache"));
164 if (HeaderP
->Signature
!= DefHeader
.Signature
||
165 HeaderP
->Dirty
== true)
166 return _error
->Error(_("The package cache file is corrupted"));
168 if (HeaderP
->MajorVersion
!= DefHeader
.MajorVersion
||
169 HeaderP
->MinorVersion
!= DefHeader
.MinorVersion
||
170 HeaderP
->CheckSizes(DefHeader
) == false)
171 return _error
->Error(_("The package cache file is an incompatible version"));
173 if (Map
.Size() < HeaderP
->CacheFileSize
)
174 return _error
->Error(_("The package cache file is corrupted, it is too small"));
176 if (HeaderP
->VerSysName
== 0 || HeaderP
->Architecture
== 0 || HeaderP
->GetArchitectures() == 0)
177 return _error
->Error(_("The package cache file is corrupted"));
180 if ((VS
= pkgVersioningSystem::GetVS(StrP
+ HeaderP
->VerSysName
)) == 0)
181 return _error
->Error(_("This APT does not support the versioning system '%s'"),StrP
+ HeaderP
->VerSysName
);
183 // Check the architecture
184 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
185 std::vector
<std::string
>::const_iterator a
= archs
.begin();
186 std::string list
= *a
;
187 for (++a
; a
!= archs
.end(); ++a
)
188 list
.append(",").append(*a
);
189 if (_config
->Find("APT::Architecture") != StrP
+ HeaderP
->Architecture
||
190 list
!= StrP
+ HeaderP
->GetArchitectures())
191 return _error
->Error(_("The package cache was built for different architectures: %s vs %s"), StrP
+ HeaderP
->GetArchitectures(), list
.c_str());
196 // Cache::Hash - Hash a string /*{{{*/
197 // ---------------------------------------------------------------------
198 /* This is used to generate the hash entries for the HashTable. With my
199 package list from bo this function gets 94% table usage on a 512 item
200 table (480 used items) */
201 map_id_t
pkgCache::sHash(const string
&Str
) const
203 unsigned long Hash
= 0;
204 for (string::const_iterator I
= Str
.begin(); I
!= Str
.end(); ++I
)
205 Hash
= 41 * Hash
+ tolower_ascii(*I
);
206 return Hash
% HeaderP
->GetHashTableSize();
209 map_id_t
pkgCache::sHash(const char *Str
) const
211 unsigned long Hash
= tolower_ascii(*Str
);
212 for (const char *I
= Str
+ 1; *I
!= 0; ++I
)
213 Hash
= 41 * Hash
+ tolower_ascii(*I
);
214 return Hash
% HeaderP
->GetHashTableSize();
217 // Cache::SingleArchFindPkg - Locate a package by name /*{{{*/
218 // ---------------------------------------------------------------------
219 /* Returns 0 on error, pointer to the package otherwise
220 The multiArch enabled methods will fallback to this one as it is (a bit)
221 faster for single arch environments and realworld is mostly singlearch… */
222 pkgCache::PkgIterator
pkgCache::SingleArchFindPkg(const string
&Name
)
224 // Look at the hash bucket
225 Package
*Pkg
= PkgP
+ HeaderP
->PkgHashTableP()[Hash(Name
)];
226 for (; Pkg
!= PkgP
; Pkg
= PkgP
+ Pkg
->NextPackage
)
228 int const cmp
= strcmp(Name
.c_str(), StrP
+ (GrpP
+ Pkg
->Group
)->Name
);
230 return PkgIterator(*this, Pkg
);
234 return PkgIterator(*this,0);
237 // Cache::FindPkg - Locate a package by name /*{{{*/
238 // ---------------------------------------------------------------------
239 /* Returns 0 on error, pointer to the package otherwise */
240 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
) {
241 size_t const found
= Name
.find(':');
242 if (found
== string::npos
)
243 return FindPkg(Name
, "native");
244 string
const Arch
= Name
.substr(found
+1);
245 /* Beware: This is specialcased to handle pkg:any in dependencies as
246 these are linked to virtual pkg:any named packages with all archs.
247 If you want any arch from a given pkg, use FindPkg(pkg,arch) */
249 return FindPkg(Name
, "any");
250 return FindPkg(Name
.substr(0, found
), Arch
);
253 // Cache::FindPkg - Locate a package by name /*{{{*/
254 // ---------------------------------------------------------------------
255 /* Returns 0 on error, pointer to the package otherwise */
256 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
, string
const &Arch
) {
257 /* We make a detour via the GrpIterator here as
258 on a multi-arch environment a group is easier to
259 find than a package (less entries in the buckets) */
260 pkgCache::GrpIterator Grp
= FindGrp(Name
);
261 if (Grp
.end() == true)
262 return PkgIterator(*this,0);
264 return Grp
.FindPkg(Arch
);
267 // Cache::FindGrp - Locate a group by name /*{{{*/
268 // ---------------------------------------------------------------------
269 /* Returns End-Pointer on error, pointer to the group otherwise */
270 pkgCache::GrpIterator
pkgCache::FindGrp(const string
&Name
) {
271 if (unlikely(Name
.empty() == true))
272 return GrpIterator(*this,0);
274 // Look at the hash bucket for the group
275 Group
*Grp
= GrpP
+ HeaderP
->GrpHashTableP()[sHash(Name
)];
276 for (; Grp
!= GrpP
; Grp
= GrpP
+ Grp
->Next
) {
277 int const cmp
= strcmp(Name
.c_str(), StrP
+ Grp
->Name
);
279 return GrpIterator(*this, Grp
);
284 return GrpIterator(*this,0);
287 // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
288 // ---------------------------------------------------------------------
289 /* This returns a string representation of the dependency compare
290 type in the weird debian style.. */
291 const char *pkgCache::CompTypeDeb(unsigned char Comp
)
293 const char * const Ops
[] = {"","<=",">=","<<",">>","=","!="};
294 if (unlikely((unsigned)(Comp
& 0xF) >= sizeof(Ops
)/sizeof(Ops
[0])))
296 return Ops
[Comp
& 0xF];
299 // Cache::CompType - Return a string describing the compare type /*{{{*/
300 // ---------------------------------------------------------------------
301 /* This returns a string representation of the dependency compare
303 const char *pkgCache::CompType(unsigned char Comp
)
305 const char * const Ops
[] = {"","<=",">=","<",">","=","!="};
306 if (unlikely((unsigned)(Comp
& 0xF) >= sizeof(Ops
)/sizeof(Ops
[0])))
308 return Ops
[Comp
& 0xF];
311 // Cache::DepType - Return a string describing the dep type /*{{{*/
312 // ---------------------------------------------------------------------
314 const char *pkgCache::DepType(unsigned char Type
)
316 const char *Types
[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
317 _("Recommends"),_("Conflicts"),_("Replaces"),
318 _("Obsoletes"),_("Breaks"), _("Enhances")};
319 if (Type
< sizeof(Types
)/sizeof(*Types
))
324 // Cache::Priority - Convert a priority value to a string /*{{{*/
325 // ---------------------------------------------------------------------
327 const char *pkgCache::Priority(unsigned char Prio
)
329 const char *Mapping
[] = {0,_("important"),_("required"),_("standard"),
330 _("optional"),_("extra")};
331 if (Prio
< _count(Mapping
))
332 return Mapping
[Prio
];
336 // GrpIterator::FindPkg - Locate a package by arch /*{{{*/
337 // ---------------------------------------------------------------------
338 /* Returns an End-Pointer on error, pointer to the package otherwise */
339 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPkg(string Arch
) const {
340 if (unlikely(IsGood() == false || S
->FirstPackage
== 0))
341 return PkgIterator(*Owner
, 0);
343 /* If we accept any package we simply return the "first"
344 package in this group (the last one added). */
346 return PkgIterator(*Owner
, Owner
->PkgP
+ S
->FirstPackage
);
348 char const* const myArch
= Owner
->NativeArch();
349 /* Most of the time the package for our native architecture is
350 the one we add at first to the cache, but this would be the
351 last one we check, so we do it now. */
352 if (Arch
== "native" || Arch
== myArch
|| Arch
== "all") {
353 pkgCache::Package
*Pkg
= Owner
->PkgP
+ S
->LastPackage
;
354 if (strcmp(myArch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
355 return PkgIterator(*Owner
, Pkg
);
359 // Iterate over the list to find the matching arch
360 for (pkgCache::Package
*Pkg
= PackageList(); Pkg
!= Owner
->PkgP
;
361 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
362 if (stringcmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
363 return PkgIterator(*Owner
, Pkg
);
364 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
368 return PkgIterator(*Owner
, 0);
371 // GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/
372 // ---------------------------------------------------------------------
373 /* Returns an End-Pointer on error, pointer to the package otherwise */
374 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual
) const {
375 pkgCache::PkgIterator Pkg
= FindPkg("native");
376 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
379 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
380 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
381 a
!= archs
.end(); ++a
) {
383 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
386 // packages without an architecture
387 Pkg
= FindPkg("none");
388 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
391 if (PreferNonVirtual
== true)
392 return FindPreferredPkg(false);
393 return PkgIterator(*Owner
, 0);
396 // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
397 // ---------------------------------------------------------------------
398 /* Returns an End-Pointer on error, pointer to the package otherwise.
399 We can't simply ++ to the next as the next package of the last will
400 be from a different group (with the same hash value) */
401 pkgCache::PkgIterator
pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator
const &LastPkg
) const {
402 if (unlikely(IsGood() == false || S
->FirstPackage
== 0 ||
403 LastPkg
.end() == true))
404 return PkgIterator(*Owner
, 0);
406 if (S
->LastPackage
== LastPkg
.Index())
407 return PkgIterator(*Owner
, 0);
409 return PkgIterator(*Owner
, Owner
->PkgP
+ LastPkg
->NextPackage
);
412 // GrpIterator::operator++ - Prefix incr /*{{{*/
413 // ---------------------------------------------------------------------
414 /* This will advance to the next logical group in the hash table. */
415 pkgCache::GrpIterator
& pkgCache::GrpIterator::operator++()
417 // Follow the current links
418 if (S
!= Owner
->GrpP
)
419 S
= Owner
->GrpP
+ S
->Next
;
421 // Follow the hash table
422 while (S
== Owner
->GrpP
&& (HashIndex
+1) < (signed)Owner
->HeaderP
->GetHashTableSize())
425 S
= Owner
->GrpP
+ Owner
->HeaderP
->GrpHashTableP()[HashIndex
];
430 // PkgIterator::operator++ - Prefix incr /*{{{*/
431 // ---------------------------------------------------------------------
432 /* This will advance to the next logical package in the hash table. */
433 pkgCache::PkgIterator
& pkgCache::PkgIterator::operator++()
435 // Follow the current links
436 if (S
!= Owner
->PkgP
)
437 S
= Owner
->PkgP
+ S
->NextPackage
;
439 // Follow the hash table
440 while (S
== Owner
->PkgP
&& (HashIndex
+1) < (signed)Owner
->HeaderP
->GetHashTableSize())
443 S
= Owner
->PkgP
+ Owner
->HeaderP
->PkgHashTableP()[HashIndex
];
448 pkgCache::DepIterator
& pkgCache::DepIterator::operator++() /*{{{*/
450 if (S
== Owner
->DepP
)
452 S
= Owner
->DepP
+ (Type
== DepVer
? S
->NextDepends
: S
->NextRevDepends
);
453 if (S
== Owner
->DepP
)
454 S2
= Owner
->DepDataP
;
456 S2
= Owner
->DepDataP
+ S
->DependencyData
;
460 // PkgIterator::State - Check the State of the package /*{{{*/
461 // ---------------------------------------------------------------------
462 /* By this we mean if it is either cleanly installed or cleanly removed. */
463 pkgCache::PkgIterator::OkState
pkgCache::PkgIterator::State() const
465 if (S
->InstState
== pkgCache::State::ReInstReq
||
466 S
->InstState
== pkgCache::State::HoldReInstReq
)
469 if (S
->CurrentState
== pkgCache::State::UnPacked
||
470 S
->CurrentState
== pkgCache::State::HalfConfigured
)
471 // we leave triggers alone complettely. dpkg deals with
472 // them in a hard-to-predict manner and if they get
473 // resolved by dpkg before apt run dpkg --configure on
474 // the TriggersPending package dpkg returns a error
475 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
476 //Pkg->CurrentState == pkgCache::State::TriggersPending)
477 return NeedsConfigure
;
479 if (S
->CurrentState
== pkgCache::State::HalfInstalled
||
480 S
->InstState
!= pkgCache::State::Ok
)
486 // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
487 // ---------------------------------------------------------------------
488 /* Return string representing of the candidate version. */
490 pkgCache::PkgIterator::CandVersion() const
492 //TargetVer is empty, so don't use it.
493 VerIterator version
= pkgPolicy(Owner
).GetCandidateVer(*this);
494 if (version
.IsGood())
495 return version
.VerStr();
499 // PkgIterator::CurVersion - Returns the current version string /*{{{*/
500 // ---------------------------------------------------------------------
501 /* Return string representing of the current version. */
503 pkgCache::PkgIterator::CurVersion() const
505 VerIterator version
= CurrentVer();
506 if (version
.IsGood())
507 return CurrentVer().VerStr();
511 // ostream operator to handle string representation of a package /*{{{*/
512 // ---------------------------------------------------------------------
513 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
514 Note that the characters <|>() are all literal above. Versions will be omitted
515 if they provide no new information (e.g. there is no newer version than candidate)
516 If no version and/or section can be found "none" is used. */
518 operator<<(std::ostream
& out
, pkgCache::PkgIterator Pkg
)
520 if (Pkg
.end() == true)
521 return out
<< "invalid package";
523 string current
= string(Pkg
.CurVersion() == 0 ? "none" : Pkg
.CurVersion());
524 string candidate
= string(Pkg
.CandVersion() == 0 ? "none" : Pkg
.CandVersion());
525 string newest
= string(Pkg
.VersionList().end() ? "none" : Pkg
.VersionList().VerStr());
527 out
<< Pkg
.Name() << " [ " << Pkg
.Arch() << " ] < " << current
;
528 if (current
!= candidate
)
529 out
<< " -> " << candidate
;
530 if ( newest
!= "none" && candidate
!= newest
)
531 out
<< " | " << newest
;
532 if (Pkg
->VersionList
== 0)
533 out
<< " > ( none )";
535 out
<< " > ( " << string(Pkg
.VersionList().Section()==0?"unknown":Pkg
.VersionList().Section()) << " )";
539 // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/
540 // ---------------------------------------------------------------------
541 /* Returns a name:arch string */
542 std::string
pkgCache::PkgIterator::FullName(bool const &Pretty
) const
544 string fullname
= Name();
545 if (Pretty
== false ||
546 (strcmp(Arch(), "all") != 0 &&
547 strcmp(Owner
->NativeArch(), Arch()) != 0))
548 return fullname
.append(":").append(Arch());
552 // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
553 // ---------------------------------------------------------------------
554 /* Currently critical deps are defined as depends, predepends and
555 conflicts (including dpkg's Breaks fields). */
556 bool pkgCache::DepIterator::IsCritical() const
558 if (IsNegative() == true ||
559 S2
->Type
== pkgCache::Dep::Depends
||
560 S2
->Type
== pkgCache::Dep::PreDepends
)
565 // DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/
566 // ---------------------------------------------------------------------
567 /* Some dependencies are positive like Depends and Recommends, others
568 are negative like Conflicts which can and should be handled differently */
569 bool pkgCache::DepIterator::IsNegative() const
571 return S2
->Type
== Dep::DpkgBreaks
||
572 S2
->Type
== Dep::Conflicts
||
573 S2
->Type
== Dep::Obsoletes
;
576 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
577 // ---------------------------------------------------------------------
578 /* This intellegently looks at dep target packages and tries to figure
579 out which package should be used. This is needed to nicely handle
580 provide mapping. If the target package has no other providing packages
581 then it returned. Otherwise the providing list is looked at to
582 see if there is one one unique providing package if so it is returned.
583 Otherwise true is returned and the target package is set. The return
584 result indicates whether the node should be expandable
586 In Conjunction with the DepCache the value of Result may not be
587 super-good since the policy may have made it uninstallable. Using
588 AllTargets is better in this case. */
589 bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator
&Result
) const
591 Result
= TargetPkg();
593 // No provides at all
594 if (Result
->ProvidesList
== 0)
597 // There is the Base package and the providing ones which is at least 2
598 if (Result
->VersionList
!= 0)
601 /* We have to skip over indirect provisions of the package that
602 owns the dependency. For instance, if libc5-dev depends on the
603 virtual package libc-dev which is provided by libc5-dev and libc6-dev
604 we must ignore libc5-dev when considering the provides list. */
605 PrvIterator PStart
= Result
.ProvidesList();
606 for (; PStart
.end() != true && PStart
.OwnerPkg() == ParentPkg(); ++PStart
);
608 // Nothing but indirect self provides
609 if (PStart
.end() == true)
612 // Check for single packages in the provides list
613 PrvIterator P
= PStart
;
614 for (; P
.end() != true; ++P
)
616 // Skip over self provides
617 if (P
.OwnerPkg() == ParentPkg())
619 if (PStart
.OwnerPkg() != P
.OwnerPkg())
623 Result
= PStart
.OwnerPkg();
625 // Check for non dups
632 // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
633 // ---------------------------------------------------------------------
634 /* This is a more useful version of TargetPkg() that follows versioned
635 provides. It includes every possible package-version that could satisfy
636 the dependency. The last item in the list has a 0. The resulting pointer
637 must be delete [] 'd */
638 pkgCache::Version
**pkgCache::DepIterator::AllTargets() const
641 unsigned long Size
=0;
645 PkgIterator DPkg
= TargetPkg();
647 // Walk along the actual package providing versions
648 for (VerIterator I
= DPkg
.VersionList(); I
.end() == false; ++I
)
650 if (IsIgnorable(I
.ParentPkg()) == true)
652 if (IsSatisfied(I
) == false)
660 // Follow all provides
661 for (PrvIterator I
= DPkg
.ProvidesList(); I
.end() == false; ++I
)
663 if (IsIgnorable(I
) == true)
665 if (IsSatisfied(I
) == false)
670 *End
++ = I
.OwnerVer();
673 // Do it again and write it into the array
676 Res
= new Version
*[Size
+1];
689 // DepIterator::GlobOr - Compute an OR group /*{{{*/
690 // ---------------------------------------------------------------------
691 /* This Takes an iterator, iterates past the current dependency grouping
692 and returns Start and End so that so End is the final element
693 in the group, if End == Start then D is End++ and End is the
694 dependency D was pointing to. Use in loops to iterate sensibly. */
695 void pkgCache::DepIterator::GlobOr(DepIterator
&Start
,DepIterator
&End
)
697 // Compute a single dependency element (glob or)
700 for (bool LastOR
= true; end() == false && LastOR
== true;)
702 LastOR
= (S2
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
709 // DepIterator::IsIgnorable - should this packag/providr be ignored? /*{{{*/
710 // ---------------------------------------------------------------------
711 /* Deps like self-conflicts should be ignored as well as implicit conflicts
712 on virtual packages. */
713 bool pkgCache::DepIterator::IsIgnorable(PkgIterator
const &PT
) const
715 if (IsNegative() == false)
718 pkgCache::PkgIterator
const PP
= ParentPkg();
719 if (PP
->Group
!= PT
->Group
)
724 pkgCache::VerIterator
const PV
= ParentVer();
725 // ignore group-conflict on a M-A:same package - but not our implicit dependencies
726 // so that we can have M-A:same packages conflicting with their own real name
727 if ((PV
->MultiArch
& pkgCache::Version::Same
) == pkgCache::Version::Same
)
729 // Replaces: ${self}:other ( << ${binary:Version})
730 if (S2
->Type
== pkgCache::Dep::Replaces
)
732 if (S2
->CompareOp
== pkgCache::Dep::Less
&& strcmp(PV
.VerStr(), TargetVer()) == 0)
735 // Breaks: ${self}:other (!= ${binary:Version})
736 else if (S2
->Type
== pkgCache::Dep::DpkgBreaks
)
738 if (S2
->CompareOp
== pkgCache::Dep::NotEquals
&& strcmp(PV
.VerStr(), TargetVer()) == 0)
746 bool pkgCache::DepIterator::IsIgnorable(PrvIterator
const &Prv
) const
748 if (IsNegative() == false)
751 PkgIterator
const Pkg
= ParentPkg();
752 /* Provides may never be applied against the same package (or group)
753 if it is a conflicts. See the comment above. */
754 if (Prv
.OwnerPkg()->Group
== Pkg
->Group
)
756 // Implicit group-conflicts should not be applied on providers of other groups
757 if (Pkg
->Group
== TargetPkg()->Group
&& Prv
.OwnerPkg()->Group
!= Pkg
->Group
)
763 // DepIterator::IsMultiArchImplicit - added by the cache generation /*{{{*/
764 // ---------------------------------------------------------------------
765 /* MultiArch can be translated to SingleArch for an resolver and we did so,
766 by adding dependencies to help the resolver understand the problem, but
767 sometimes it is needed to identify these to ignore them… */
768 bool pkgCache::DepIterator::IsMultiArchImplicit() const
770 if (ParentPkg()->Arch
!= TargetPkg()->Arch
&&
771 (S2
->Type
== pkgCache::Dep::Replaces
||
772 S2
->Type
== pkgCache::Dep::DpkgBreaks
||
773 S2
->Type
== pkgCache::Dep::Conflicts
))
778 // DepIterator::IsSatisfied - check if a version satisfied the dependency /*{{{*/
779 bool pkgCache::DepIterator::IsSatisfied(VerIterator
const &Ver
) const
781 return Owner
->VS
->CheckDep(Ver
.VerStr(),S2
->CompareOp
,TargetVer());
783 bool pkgCache::DepIterator::IsSatisfied(PrvIterator
const &Prv
) const
785 return Owner
->VS
->CheckDep(Prv
.ProvideVersion(),S2
->CompareOp
,TargetVer());
788 // ostream operator to handle string representation of a dependecy /*{{{*/
789 // ---------------------------------------------------------------------
791 std::ostream
& operator<<(std::ostream
& out
, pkgCache::DepIterator D
)
794 return out
<< "invalid dependency";
796 pkgCache::PkgIterator P
= D
.ParentPkg();
797 pkgCache::PkgIterator T
= D
.TargetPkg();
799 out
<< (P
.end() ? "invalid pkg" : P
.FullName(false)) << " " << D
.DepType()
802 out
<< "invalid pkg";
807 out
<< " (" << D
.CompType() << " " << D
.TargetVer() << ")";
812 // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
813 // ---------------------------------------------------------------------
814 /* This just looks over the version list to see if B is listed before A. In
815 most cases this will return in under 4 checks, ver lists are short. */
816 int pkgCache::VerIterator::CompareVer(const VerIterator
&B
) const
818 // Check if they are equal
826 /* Start at A and look for B. If B is found then A > B otherwise
827 B was before A so A < B */
828 VerIterator I
= *this;
829 for (;I
.end() == false; ++I
)
835 // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
836 // ---------------------------------------------------------------------
838 APT_PURE
bool pkgCache::VerIterator::Downloadable() const
840 VerFileIterator Files
= FileList();
841 for (; Files
.end() == false; ++Files
)
842 if (Files
.File().Flagged(pkgCache::Flag::NotSource
) == false)
847 // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
848 // ---------------------------------------------------------------------
849 /* This checks to see if any of the versions files are not NotAutomatic.
850 True if this version is selectable for automatic installation. */
851 APT_PURE
bool pkgCache::VerIterator::Automatic() const
853 VerFileIterator Files
= FileList();
854 for (; Files
.end() == false; ++Files
)
855 // Do not check ButAutomaticUpgrades here as it is kind of automatic…
856 if (Files
.File().Flagged(pkgCache::Flag::NotAutomatic
) == false)
861 // VerIterator::NewestFile - Return the newest file version relation /*{{{*/
862 // ---------------------------------------------------------------------
863 /* This looks at the version numbers associated with all of the sources
864 this version is in and returns the highest.*/
865 pkgCache::VerFileIterator
pkgCache::VerIterator::NewestFile() const
867 VerFileIterator Files
= FileList();
868 VerFileIterator Highest
= Files
;
869 for (; Files
.end() == false; ++Files
)
871 if (Owner
->VS
->CmpReleaseVer(Files
.File().Version(),Highest
.File().Version()) > 0)
878 // VerIterator::RelStr - Release description string /*{{{*/
879 // ---------------------------------------------------------------------
880 /* This describes the version from a release-centric manner. The output is a
881 list of Label:Version/Archive */
882 string
pkgCache::VerIterator::RelStr() const
886 for (pkgCache::VerFileIterator I
= this->FileList(); I
.end() == false; ++I
)
888 // Do not print 'not source' entries'
889 pkgCache::PkgFileIterator
const File
= I
.File();
890 if (File
.Flagged(pkgCache::Flag::NotSource
))
893 // See if we have already printed this out..
895 for (pkgCache::VerFileIterator J
= this->FileList(); I
!= J
; ++J
)
897 pkgCache::PkgFileIterator
const File2
= J
.File();
898 if (File2
.Label() == 0 || File
.Label() == 0)
901 if (strcmp(File
.Label(),File2
.Label()) != 0)
904 if (File2
.Version() == File
.Version())
909 if (File2
.Version() == 0 || File
.Version() == 0)
911 if (strcmp(File
.Version(),File2
.Version()) == 0)
923 if (File
.Label() != 0)
924 Res
= Res
+ File
.Label() + ':';
926 if (File
.Archive() != 0)
928 if (File
.Version() == 0)
929 Res
+= File
.Archive();
931 Res
= Res
+ File
.Version() + '/' + File
.Archive();
935 // No release file, print the host name that this came from
936 if (File
.Site() == 0 || File
.Site()[0] == 0)
942 if (S
->ParentPkg
!= 0)
943 Res
.append(" [").append(Arch()).append("]");
947 // VerIterator::MultiArchType - string representing MultiArch flag /*{{{*/
948 const char * pkgCache::VerIterator::MultiArchType() const
950 if ((S
->MultiArch
& pkgCache::Version::Same
) == pkgCache::Version::Same
)
952 else if ((S
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
954 else if ((S
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
959 // RlsFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
960 // ---------------------------------------------------------------------
961 /* This stats the file and compares its stats with the ones that were
962 stored during generation. Date checks should probably also be
964 bool pkgCache::RlsFileIterator::IsOk()
967 if (stat(FileName(),&Buf
) != 0)
970 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
976 // RlsFileIterator::RelStr - Return the release string /*{{{*/
977 string
pkgCache::RlsFileIterator::RelStr()
981 Res
= Res
+ (Res
.empty() == true?"v=":",v=") + Version();
983 Res
= Res
+ (Res
.empty() == true?"o=":",o=") + Origin();
985 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Archive();
987 Res
= Res
+ (Res
.empty() == true?"n=":",n=") + Codename();
989 Res
= Res
+ (Res
.empty() == true?"l=":",l=") + Label();
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
998 bool pkgCache::PkgFileIterator::IsOk()
1001 if (stat(FileName(),&Buf
) != 0)
1004 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
1010 string
pkgCache::PkgFileIterator::RelStr() /*{{{*/
1013 if (ReleaseFile() == 0)
1015 if (Component() != 0)
1016 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Component();
1020 Res
= ReleaseFile().RelStr();
1021 if (Component() != 0)
1022 Res
= Res
+ (Res
.empty() == true?"c=":",c=") + Component();
1024 if (Architecture() != 0)
1025 Res
= Res
+ (Res
.empty() == true?"b=":",b=") + Architecture();
1029 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
1030 // ---------------------------------------------------------------------
1031 /* return a DescIter for the current locale or the default if none is
1034 pkgCache::DescIterator
pkgCache::VerIterator::TranslatedDescription() const
1036 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
1037 for (std::vector
<string
>::const_iterator l
= lang
.begin();
1038 l
!= lang
.end(); ++l
)
1040 pkgCache::DescIterator Desc
= DescriptionList();
1041 for (; Desc
.end() == false; ++Desc
)
1042 if (*l
== Desc
.LanguageCode())
1044 if (Desc
.end() == true)
1048 Desc
= DescriptionList();
1049 for (; Desc
.end() == false; ++Desc
)
1050 if (strcmp(Desc
.LanguageCode(), "") == 0)
1052 if (Desc
.end() == true)
1060 for (pkgCache::DescIterator Desc
= DescriptionList();
1061 Desc
.end() == false; ++Desc
)
1062 if (strcmp(Desc
.LanguageCode(), "") == 0)
1064 return DescriptionList();
1068 // PrvIterator::IsMultiArchImplicit - added by the cache generation /*{{{*/
1069 // ---------------------------------------------------------------------
1070 /* MultiArch can be translated to SingleArch for an resolver and we did so,
1071 by adding provides to help the resolver understand the problem, but
1072 sometimes it is needed to identify these to ignore them… */
1073 bool pkgCache::PrvIterator::IsMultiArchImplicit() const
1075 pkgCache::PkgIterator
const Owner
= OwnerPkg();
1076 pkgCache::PkgIterator
const Parent
= ParentPkg();
1077 if (strcmp(Owner
.Arch(), Parent
.Arch()) != 0 || Owner
.Group()->Name
== Parent
.Group()->Name
)
1083 pkgCache::~pkgCache() {}