]>
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"));
161 if (HeaderP
->VerSysName
== 0 ||
162 (VS
= pkgVersioningSystem::GetVS(StrP
+ HeaderP
->VerSysName
)) == 0)
163 return _error
->Error(_("This APT does not support the versioning system '%s'"),StrP
+ HeaderP
->VerSysName
);
165 // Chcek the arhcitecture
166 if (HeaderP
->Architecture
== 0 ||
167 _config
->Find("APT::Architecture") != StrP
+ HeaderP
->Architecture
)
168 return _error
->Error(_("The package cache was built for a different architecture"));
172 // Cache::Hash - Hash a string /*{{{*/
173 // ---------------------------------------------------------------------
174 /* This is used to generate the hash entries for the HashTable. With my
175 package list from bo this function gets 94% table usage on a 512 item
176 table (480 used items) */
177 unsigned long pkgCache::sHash(const string
&Str
) const
179 unsigned long Hash
= 0;
180 for (string::const_iterator I
= Str
.begin(); I
!= Str
.end(); I
++)
181 Hash
= 5*Hash
+ tolower_ascii(*I
);
182 return Hash
% _count(HeaderP
->PkgHashTable
);
185 unsigned long pkgCache::sHash(const char *Str
) const
187 unsigned long Hash
= 0;
188 for (const char *I
= Str
; *I
!= 0; I
++)
189 Hash
= 5*Hash
+ tolower_ascii(*I
);
190 return Hash
% _count(HeaderP
->PkgHashTable
);
194 // Cache::SingleArchFindPkg - Locate a package by name /*{{{*/
195 // ---------------------------------------------------------------------
196 /* Returns 0 on error, pointer to the package otherwise
197 The multiArch enabled methods will fallback to this one as it is (a bit)
198 faster for single arch environments and realworld is mostly singlearch… */
199 pkgCache::PkgIterator
pkgCache::SingleArchFindPkg(const string
&Name
)
201 // Look at the hash bucket
202 Package
*Pkg
= PkgP
+ HeaderP
->PkgHashTable
[Hash(Name
)];
203 for (; Pkg
!= PkgP
; Pkg
= PkgP
+ Pkg
->NextPackage
)
205 if (Pkg
->Name
!= 0 && StrP
[Pkg
->Name
] == Name
[0] &&
206 stringcasecmp(Name
,StrP
+ Pkg
->Name
) == 0)
207 return PkgIterator(*this,Pkg
);
209 return PkgIterator(*this,0);
212 // Cache::FindPkg - Locate a package by name /*{{{*/
213 // ---------------------------------------------------------------------
214 /* Returns 0 on error, pointer to the package otherwise */
215 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
) {
216 size_t const found
= Name
.find(':');
217 if (found
== string::npos
)
219 if (MultiArchCache() == false)
220 return SingleArchFindPkg(Name
);
222 return FindPkg(Name
, "native");
224 string
const Arch
= Name
.substr(found
+1);
225 /* Beware: This is specialcased to handle pkg:any in dependencies as
226 these are linked to virtual pkg:any named packages with all archs.
227 If you want any arch from a given pkg, use FindPkg(pkg,arch) */
229 return FindPkg(Name
, "any");
230 return FindPkg(Name
.substr(0, found
), Arch
);
233 // Cache::FindPkg - Locate a package by name /*{{{*/
234 // ---------------------------------------------------------------------
235 /* Returns 0 on error, pointer to the package otherwise */
236 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
, string
const &Arch
) {
237 if (MultiArchCache() == false) {
238 if (Arch
== "native" || Arch
== "all" || Arch
== "any" ||
239 Arch
== NativeArch())
240 return SingleArchFindPkg(Name
);
242 return PkgIterator(*this,0);
244 /* We make a detour via the GrpIterator here as
245 on a multi-arch environment a group is easier to
246 find than a package (less entries in the buckets) */
247 pkgCache::GrpIterator Grp
= FindGrp(Name
);
248 if (Grp
.end() == true)
249 return PkgIterator(*this,0);
251 return Grp
.FindPkg(Arch
);
254 // Cache::FindGrp - Locate a group by name /*{{{*/
255 // ---------------------------------------------------------------------
256 /* Returns End-Pointer on error, pointer to the group otherwise */
257 pkgCache::GrpIterator
pkgCache::FindGrp(const string
&Name
) {
258 if (unlikely(Name
.empty() == true))
259 return GrpIterator(*this,0);
261 // Look at the hash bucket for the group
262 Group
*Grp
= GrpP
+ HeaderP
->GrpHashTable
[sHash(Name
)];
263 for (; Grp
!= GrpP
; Grp
= GrpP
+ Grp
->Next
) {
264 if (Grp
->Name
!= 0 && StrP
[Grp
->Name
] == Name
[0] &&
265 stringcasecmp(Name
, StrP
+ Grp
->Name
) == 0)
266 return GrpIterator(*this, Grp
);
269 return GrpIterator(*this,0);
272 // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
273 // ---------------------------------------------------------------------
274 /* This returns a string representation of the dependency compare
275 type in the weird debian style.. */
276 const char *pkgCache::CompTypeDeb(unsigned char Comp
)
278 const char *Ops
[] = {"","<=",">=","<<",">>","=","!="};
279 if ((unsigned)(Comp
& 0xF) < 7)
280 return Ops
[Comp
& 0xF];
284 // Cache::CompType - Return a string describing the compare type /*{{{*/
285 // ---------------------------------------------------------------------
286 /* This returns a string representation of the dependency compare
288 const char *pkgCache::CompType(unsigned char Comp
)
290 const char *Ops
[] = {"","<=",">=","<",">","=","!="};
291 if ((unsigned)(Comp
& 0xF) < 7)
292 return Ops
[Comp
& 0xF];
296 // Cache::DepType - Return a string describing the dep type /*{{{*/
297 // ---------------------------------------------------------------------
299 const char *pkgCache::DepType(unsigned char Type
)
301 const char *Types
[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
302 _("Recommends"),_("Conflicts"),_("Replaces"),
303 _("Obsoletes"),_("Breaks"), _("Enhances")};
304 if (Type
< sizeof(Types
)/sizeof(*Types
))
309 // Cache::Priority - Convert a priority value to a string /*{{{*/
310 // ---------------------------------------------------------------------
312 const char *pkgCache::Priority(unsigned char Prio
)
314 const char *Mapping
[] = {0,_("important"),_("required"),_("standard"),
315 _("optional"),_("extra")};
316 if (Prio
< _count(Mapping
))
317 return Mapping
[Prio
];
321 // GrpIterator::FindPkg - Locate a package by arch /*{{{*/
322 // ---------------------------------------------------------------------
323 /* Returns an End-Pointer on error, pointer to the package otherwise */
324 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPkg(string Arch
) const {
325 if (unlikely(IsGood() == false || S
->FirstPackage
== 0))
326 return PkgIterator(*Owner
, 0);
328 /* If we accept any package we simply return the "first"
329 package in this group (the last one added). */
331 return PkgIterator(*Owner
, Owner
->PkgP
+ S
->FirstPackage
);
333 char const* const myArch
= Owner
->NativeArch();
334 /* Most of the time the package for our native architecture is
335 the one we add at first to the cache, but this would be the
336 last one we check, so we do it now. */
337 if (Arch
== "native" || Arch
== myArch
|| Arch
== "all") {
338 pkgCache::Package
*Pkg
= Owner
->PkgP
+ S
->LastPackage
;
339 if (strcasecmp(myArch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
340 return PkgIterator(*Owner
, Pkg
);
344 /* Iterate over the list to find the matching arch
345 unfortunately this list includes "package noise"
346 (= different packages with same calculated hash),
347 so we need to check the name also */
348 for (pkgCache::Package
*Pkg
= PackageList(); Pkg
!= Owner
->PkgP
;
349 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
350 if (S
->Name
== Pkg
->Name
&&
351 stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
352 return PkgIterator(*Owner
, Pkg
);
353 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
357 return PkgIterator(*Owner
, 0);
360 // GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/
361 // ---------------------------------------------------------------------
362 /* Returns an End-Pointer on error, pointer to the package otherwise */
363 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual
) const {
364 pkgCache::PkgIterator Pkg
= FindPkg("native");
365 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
368 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
369 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
370 a
!= archs
.end(); ++a
) {
372 if (Pkg
.end() == false && (PreferNonVirtual
== false || Pkg
->VersionList
!= 0))
376 if (PreferNonVirtual
== true)
377 return FindPreferredPkg(false);
378 return PkgIterator(*Owner
, 0);
381 // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
382 // ---------------------------------------------------------------------
383 /* Returns an End-Pointer on error, pointer to the package otherwise.
384 We can't simply ++ to the next as the next package of the last will
385 be from a different group (with the same hash value) */
386 pkgCache::PkgIterator
pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator
const &LastPkg
) const {
387 if (unlikely(IsGood() == false || S
->FirstPackage
== 0 ||
388 LastPkg
.end() == true))
389 return PkgIterator(*Owner
, 0);
391 if (S
->LastPackage
== LastPkg
.Index())
392 return PkgIterator(*Owner
, 0);
394 return PkgIterator(*Owner
, Owner
->PkgP
+ LastPkg
->NextPackage
);
397 // GrpIterator::operator ++ - Postfix incr /*{{{*/
398 // ---------------------------------------------------------------------
399 /* This will advance to the next logical group in the hash table. */
400 void pkgCache::GrpIterator::operator ++(int)
402 // Follow the current links
403 if (S
!= Owner
->GrpP
)
404 S
= Owner
->GrpP
+ S
->Next
;
406 // Follow the hash table
407 while (S
== Owner
->GrpP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->GrpHashTable
))
410 S
= Owner
->GrpP
+ Owner
->HeaderP
->GrpHashTable
[HashIndex
];
414 // PkgIterator::operator ++ - Postfix incr /*{{{*/
415 // ---------------------------------------------------------------------
416 /* This will advance to the next logical package in the hash table. */
417 void pkgCache::PkgIterator::operator ++(int)
419 // Follow the current links
420 if (S
!= Owner
->PkgP
)
421 S
= Owner
->PkgP
+ S
->NextPackage
;
423 // Follow the hash table
424 while (S
== Owner
->PkgP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->PkgHashTable
))
427 S
= Owner
->PkgP
+ Owner
->HeaderP
->PkgHashTable
[HashIndex
];
431 // PkgIterator::State - Check the State of the package /*{{{*/
432 // ---------------------------------------------------------------------
433 /* By this we mean if it is either cleanly installed or cleanly removed. */
434 pkgCache::PkgIterator::OkState
pkgCache::PkgIterator::State() const
436 if (S
->InstState
== pkgCache::State::ReInstReq
||
437 S
->InstState
== pkgCache::State::HoldReInstReq
)
440 if (S
->CurrentState
== pkgCache::State::UnPacked
||
441 S
->CurrentState
== pkgCache::State::HalfConfigured
)
442 // we leave triggers alone complettely. dpkg deals with
443 // them in a hard-to-predict manner and if they get
444 // resolved by dpkg before apt run dpkg --configure on
445 // the TriggersPending package dpkg returns a error
446 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
447 //Pkg->CurrentState == pkgCache::State::TriggersPending)
448 return NeedsConfigure
;
450 if (S
->CurrentState
== pkgCache::State::HalfInstalled
||
451 S
->InstState
!= pkgCache::State::Ok
)
457 // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
458 // ---------------------------------------------------------------------
459 /* Return string representing of the candidate version. */
461 pkgCache::PkgIterator::CandVersion() const
463 //TargetVer is empty, so don't use it.
464 VerIterator version
= pkgPolicy(Owner
).GetCandidateVer(*this);
465 if (version
.IsGood())
466 return version
.VerStr();
470 // PkgIterator::CurVersion - Returns the current version string /*{{{*/
471 // ---------------------------------------------------------------------
472 /* Return string representing of the current version. */
474 pkgCache::PkgIterator::CurVersion() const
476 VerIterator version
= CurrentVer();
477 if (version
.IsGood())
478 return CurrentVer().VerStr();
482 // ostream operator to handle string representation of a package /*{{{*/
483 // ---------------------------------------------------------------------
484 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
485 Note that the characters <|>() are all literal above. Versions will be ommited
486 if they provide no new information (e.g. there is no newer version than candidate)
487 If no version and/or section can be found "none" is used. */
489 operator<<(ostream
& out
, pkgCache::PkgIterator Pkg
)
491 if (Pkg
.end() == true)
492 return out
<< "invalid package";
494 string current
= string(Pkg
.CurVersion() == 0 ? "none" : Pkg
.CurVersion());
495 string candidate
= string(Pkg
.CandVersion() == 0 ? "none" : Pkg
.CandVersion());
496 string newest
= string(Pkg
.VersionList().end() ? "none" : Pkg
.VersionList().VerStr());
498 out
<< Pkg
.Name() << " [ " << Pkg
.Arch() << " ] < " << current
;
499 if (current
!= candidate
)
500 out
<< " -> " << candidate
;
501 if ( newest
!= "none" && candidate
!= newest
)
502 out
<< " | " << newest
;
503 out
<< " > ( " << string(Pkg
.Section()==0?"none":Pkg
.Section()) << " )";
507 // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/
508 // ---------------------------------------------------------------------
509 /* Returns a name:arch string */
510 std::string
pkgCache::PkgIterator::FullName(bool const &Pretty
) const
512 string fullname
= Name();
513 if (Pretty
== false ||
514 (strcmp(Arch(), "all") != 0 &&
515 strcmp(Owner
->NativeArch(), Arch()) != 0))
516 return fullname
.append(":").append(Arch());
520 // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
521 // ---------------------------------------------------------------------
522 /* Currently critical deps are defined as depends, predepends and
523 conflicts (including dpkg's Breaks fields). */
524 bool pkgCache::DepIterator::IsCritical() const
526 if (IsNegative() == true ||
527 S
->Type
== pkgCache::Dep::Depends
||
528 S
->Type
== pkgCache::Dep::PreDepends
)
533 // DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/
534 // ---------------------------------------------------------------------
535 /* Some dependencies are positive like Depends and Recommends, others
536 are negative like Conflicts which can and should be handled differently */
537 bool pkgCache::DepIterator::IsNegative() const
539 return S
->Type
== Dep::DpkgBreaks
||
540 S
->Type
== Dep::Conflicts
||
541 S
->Type
== Dep::Obsoletes
;
544 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
545 // ---------------------------------------------------------------------
546 /* This intellegently looks at dep target packages and tries to figure
547 out which package should be used. This is needed to nicely handle
548 provide mapping. If the target package has no other providing packages
549 then it returned. Otherwise the providing list is looked at to
550 see if there is one one unique providing package if so it is returned.
551 Otherwise true is returned and the target package is set. The return
552 result indicates whether the node should be expandable
554 In Conjunction with the DepCache the value of Result may not be
555 super-good since the policy may have made it uninstallable. Using
556 AllTargets is better in this case. */
557 bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator
&Result
) const
559 Result
= TargetPkg();
561 // No provides at all
562 if (Result
->ProvidesList
== 0)
565 // There is the Base package and the providing ones which is at least 2
566 if (Result
->VersionList
!= 0)
569 /* We have to skip over indirect provisions of the package that
570 owns the dependency. For instance, if libc5-dev depends on the
571 virtual package libc-dev which is provided by libc5-dev and libc6-dev
572 we must ignore libc5-dev when considering the provides list. */
573 PrvIterator PStart
= Result
.ProvidesList();
574 for (; PStart
.end() != true && PStart
.OwnerPkg() == ParentPkg(); PStart
++);
576 // Nothing but indirect self provides
577 if (PStart
.end() == true)
580 // Check for single packages in the provides list
581 PrvIterator P
= PStart
;
582 for (; P
.end() != true; P
++)
584 // Skip over self provides
585 if (P
.OwnerPkg() == ParentPkg())
587 if (PStart
.OwnerPkg() != P
.OwnerPkg())
591 Result
= PStart
.OwnerPkg();
593 // Check for non dups
600 // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
601 // ---------------------------------------------------------------------
602 /* This is a more useful version of TargetPkg() that follows versioned
603 provides. It includes every possible package-version that could satisfy
604 the dependency. The last item in the list has a 0. The resulting pointer
605 must be delete [] 'd */
606 pkgCache::Version
**pkgCache::DepIterator::AllTargets() const
609 unsigned long Size
=0;
613 PkgIterator DPkg
= TargetPkg();
615 // Walk along the actual package providing versions
616 for (VerIterator I
= DPkg
.VersionList(); I
.end() == false; I
++)
618 if (Owner
->VS
->CheckDep(I
.VerStr(),S
->CompareOp
,TargetVer()) == false)
621 if (IsNegative() == true &&
622 ParentPkg() == I
.ParentPkg())
630 // Follow all provides
631 for (PrvIterator I
= DPkg
.ProvidesList(); I
.end() == false; I
++)
633 if (Owner
->VS
->CheckDep(I
.ProvideVersion(),S
->CompareOp
,TargetVer()) == false)
636 if (IsNegative() == true &&
637 ParentPkg() == I
.OwnerPkg())
642 *End
++ = I
.OwnerVer();
645 // Do it again and write it into the array
648 Res
= new Version
*[Size
+1];
661 // DepIterator::GlobOr - Compute an OR group /*{{{*/
662 // ---------------------------------------------------------------------
663 /* This Takes an iterator, iterates past the current dependency grouping
664 and returns Start and End so that so End is the final element
665 in the group, if End == Start then D is End++ and End is the
666 dependency D was pointing to. Use in loops to iterate sensibly. */
667 void pkgCache::DepIterator::GlobOr(DepIterator
&Start
,DepIterator
&End
)
669 // Compute a single dependency element (glob or)
672 for (bool LastOR
= true; end() == false && LastOR
== true;)
674 LastOR
= (S
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
681 // ostream operator to handle string representation of a dependecy /*{{{*/
682 // ---------------------------------------------------------------------
684 std::ostream
& operator<<(ostream
& out
, pkgCache::DepIterator D
)
687 return out
<< "invalid dependency";
689 pkgCache::PkgIterator P
= D
.ParentPkg();
690 pkgCache::PkgIterator T
= D
.TargetPkg();
692 out
<< (P
.end() ? "invalid pkg" : P
.FullName(false)) << " " << D
.DepType()
695 out
<< "invalid pkg";
700 out
<< " (" << D
.CompType() << " " << D
.TargetVer() << ")";
705 // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
706 // ---------------------------------------------------------------------
707 /* This just looks over the version list to see if B is listed before A. In
708 most cases this will return in under 4 checks, ver lists are short. */
709 int pkgCache::VerIterator::CompareVer(const VerIterator
&B
) const
711 // Check if they are equal
719 /* Start at A and look for B. If B is found then A > B otherwise
720 B was before A so A < B */
721 VerIterator I
= *this;
722 for (;I
.end() == false; I
++)
728 // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
729 // ---------------------------------------------------------------------
731 bool pkgCache::VerIterator::Downloadable() const
733 VerFileIterator Files
= FileList();
734 for (; Files
.end() == false; Files
++)
735 if ((Files
.File()->Flags
& pkgCache::Flag::NotSource
) != pkgCache::Flag::NotSource
)
740 // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
741 // ---------------------------------------------------------------------
742 /* This checks to see if any of the versions files are not NotAutomatic.
743 True if this version is selectable for automatic installation. */
744 bool pkgCache::VerIterator::Automatic() const
746 VerFileIterator Files
= FileList();
747 for (; Files
.end() == false; Files
++)
748 // Do not check ButAutomaticUpgrades here as it is kind of automatic…
749 if ((Files
.File()->Flags
& pkgCache::Flag::NotAutomatic
) != pkgCache::Flag::NotAutomatic
)
754 // VerIterator::NewestFile - Return the newest file version relation /*{{{*/
755 // ---------------------------------------------------------------------
756 /* This looks at the version numbers associated with all of the sources
757 this version is in and returns the highest.*/
758 pkgCache::VerFileIterator
pkgCache::VerIterator::NewestFile() const
760 VerFileIterator Files
= FileList();
761 VerFileIterator Highest
= Files
;
762 for (; Files
.end() == false; Files
++)
764 if (Owner
->VS
->CmpReleaseVer(Files
.File().Version(),Highest
.File().Version()) > 0)
771 // VerIterator::RelStr - Release description string /*{{{*/
772 // ---------------------------------------------------------------------
773 /* This describes the version from a release-centric manner. The output is a
774 list of Label:Version/Archive */
775 string
pkgCache::VerIterator::RelStr() const
779 for (pkgCache::VerFileIterator I
= this->FileList(); I
.end() == false; I
++)
781 // Do not print 'not source' entries'
782 pkgCache::PkgFileIterator File
= I
.File();
783 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
786 // See if we have already printed this out..
788 for (pkgCache::VerFileIterator J
= this->FileList(); I
!= J
; J
++)
790 pkgCache::PkgFileIterator File2
= J
.File();
791 if (File2
->Label
== 0 || File
->Label
== 0)
794 if (strcmp(File
.Label(),File2
.Label()) != 0)
797 if (File2
->Version
== File
->Version
)
802 if (File2
->Version
== 0 || File
->Version
== 0)
804 if (strcmp(File
.Version(),File2
.Version()) == 0)
816 if (File
->Label
!= 0)
817 Res
= Res
+ File
.Label() + ':';
819 if (File
->Archive
!= 0)
821 if (File
->Version
== 0)
822 Res
+= File
.Archive();
824 Res
= Res
+ File
.Version() + '/' + File
.Archive();
828 // No release file, print the host name that this came from
829 if (File
->Site
== 0 || File
.Site()[0] == 0)
835 if (S
->ParentPkg
!= 0)
836 Res
.append(" [").append(Arch()).append("]");
840 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
841 // ---------------------------------------------------------------------
842 /* This stats the file and compares its stats with the ones that were
843 stored during generation. Date checks should probably also be
845 bool pkgCache::PkgFileIterator::IsOk()
848 if (stat(FileName(),&Buf
) != 0)
851 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
857 // PkgFileIterator::RelStr - Return the release string /*{{{*/
858 // ---------------------------------------------------------------------
860 string
pkgCache::PkgFileIterator::RelStr()
864 Res
= Res
+ (Res
.empty() == true?"v=":",v=") + Version();
866 Res
= Res
+ (Res
.empty() == true?"o=":",o=") + Origin();
868 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Archive();
870 Res
= Res
+ (Res
.empty() == true?"n=":",n=") + Codename();
872 Res
= Res
+ (Res
.empty() == true?"l=":",l=") + Label();
873 if (Component() != 0)
874 Res
= Res
+ (Res
.empty() == true?"c=":",c=") + Component();
875 if (Architecture() != 0)
876 Res
= Res
+ (Res
.empty() == true?"b=":",b=") + Architecture();
880 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
881 // ---------------------------------------------------------------------
882 /* return a DescIter for the current locale or the default if none is
885 pkgCache::DescIterator
pkgCache::VerIterator::TranslatedDescription() const
887 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
888 for (std::vector
<string
>::const_iterator l
= lang
.begin();
889 l
!= lang
.end(); l
++)
891 pkgCache::DescIterator Desc
= DescriptionList();
892 for (; Desc
.end() == false; ++Desc
)
893 if (*l
== Desc
.LanguageCode() ||
894 (*l
== "en" && strcmp(Desc
.LanguageCode(),"") == 0))
896 if (Desc
.end() == true)
900 for (pkgCache::DescIterator Desc
= DescriptionList();
901 Desc
.end() == false; ++Desc
)
902 if (strcmp(Desc
.LanguageCode(), "") == 0)
904 return DescriptionList();