]>
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 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
);
82 memset(PkgHashTable
,0,sizeof(PkgHashTable
));
83 memset(GrpHashTable
,0,sizeof(GrpHashTable
));
84 memset(Pools
,0,sizeof(Pools
));
87 // Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/
88 // ---------------------------------------------------------------------
90 bool pkgCache::Header::CheckSizes(Header
&Against
) const
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
)
106 // Cache::pkgCache - Constructor /*{{{*/
107 // ---------------------------------------------------------------------
109 pkgCache::pkgCache(MMap
*Map
, bool DoMap
) : Map(*Map
)
111 MultiArchEnabled
= APT::Configuration::getArchitectures().size() > 1;
116 // Cache::ReMap - Reopen the cache file /*{{{*/
117 // ---------------------------------------------------------------------
118 /* If the file is already closed then this will open it open it. */
119 bool pkgCache::ReMap()
121 // Apply the typecasts.
122 HeaderP
= (Header
*)Map
.Data();
123 GrpP
= (Group
*)Map
.Data();
124 PkgP
= (Package
*)Map
.Data();
125 VerFileP
= (VerFile
*)Map
.Data();
126 DescFileP
= (DescFile
*)Map
.Data();
127 PkgFileP
= (PackageFile
*)Map
.Data();
128 VerP
= (Version
*)Map
.Data();
129 DescP
= (Description
*)Map
.Data();
130 ProvideP
= (Provides
*)Map
.Data();
131 DepP
= (Dependency
*)Map
.Data();
132 StringItemP
= (StringItem
*)Map
.Data();
133 StrP
= (char *)Map
.Data();
135 if (Map
.Size() == 0 || HeaderP
== 0)
136 return _error
->Error(_("Empty package cache"));
140 if (HeaderP
->Signature
!= DefHeader
.Signature
||
141 HeaderP
->Dirty
== true)
142 return _error
->Error(_("The package cache file is corrupted"));
144 if (HeaderP
->MajorVersion
!= DefHeader
.MajorVersion
||
145 HeaderP
->MinorVersion
!= DefHeader
.MinorVersion
||
146 HeaderP
->CheckSizes(DefHeader
) == false)
147 return _error
->Error(_("The package cache file is an incompatible version"));
150 if (HeaderP
->VerSysName
== 0 ||
151 (VS
= pkgVersioningSystem::GetVS(StrP
+ HeaderP
->VerSysName
)) == 0)
152 return _error
->Error(_("This APT does not support the versioning system '%s'"),StrP
+ HeaderP
->VerSysName
);
154 // Chcek the arhcitecture
155 if (HeaderP
->Architecture
== 0 ||
156 _config
->Find("APT::Architecture") != StrP
+ HeaderP
->Architecture
)
157 return _error
->Error(_("The package cache was built for a different architecture"));
161 // Cache::Hash - Hash a string /*{{{*/
162 // ---------------------------------------------------------------------
163 /* This is used to generate the hash entries for the HashTable. With my
164 package list from bo this function gets 94% table usage on a 512 item
165 table (480 used items) */
166 unsigned long pkgCache::sHash(const string
&Str
) const
168 unsigned long Hash
= 0;
169 for (string::const_iterator I
= Str
.begin(); I
!= Str
.end(); I
++)
170 Hash
= 5*Hash
+ tolower_ascii(*I
);
171 return Hash
% _count(HeaderP
->PkgHashTable
);
174 unsigned long pkgCache::sHash(const char *Str
) const
176 unsigned long Hash
= 0;
177 for (const char *I
= Str
; *I
!= 0; I
++)
178 Hash
= 5*Hash
+ tolower_ascii(*I
);
179 return Hash
% _count(HeaderP
->PkgHashTable
);
183 // Cache::SingleArchFindPkg - Locate a package by name /*{{{*/
184 // ---------------------------------------------------------------------
185 /* Returns 0 on error, pointer to the package otherwise
186 The multiArch enabled methods will fallback to this one as it is (a bit)
187 faster for single arch environments and realworld is mostly singlearch… */
188 pkgCache::PkgIterator
pkgCache::SingleArchFindPkg(const string
&Name
)
190 // Look at the hash bucket
191 Package
*Pkg
= PkgP
+ HeaderP
->PkgHashTable
[Hash(Name
)];
192 for (; Pkg
!= PkgP
; Pkg
= PkgP
+ Pkg
->NextPackage
)
194 if (Pkg
->Name
!= 0 && StrP
[Pkg
->Name
] == Name
[0] &&
195 stringcasecmp(Name
,StrP
+ Pkg
->Name
) == 0)
196 return PkgIterator(*this,Pkg
);
198 return PkgIterator(*this,0);
201 // Cache::FindPkg - Locate a package by name /*{{{*/
202 // ---------------------------------------------------------------------
203 /* Returns 0 on error, pointer to the package otherwise */
204 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
) {
205 if (MultiArchCache() == false)
206 return SingleArchFindPkg(Name
);
207 size_t const found
= Name
.find(':');
208 if (found
== string::npos
)
209 return FindPkg(Name
, "native");
210 string
const Arch
= Name
.substr(found
+1);
212 return FindPkg(Name
, "any");
213 return FindPkg(Name
.substr(0, found
), Arch
);
216 // Cache::FindPkg - Locate a package by name /*{{{*/
217 // ---------------------------------------------------------------------
218 /* Returns 0 on error, pointer to the package otherwise */
219 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
, string
const &Arch
) {
220 if (MultiArchCache() == false) {
221 if (Arch
== "native" || Arch
== "all" ||
222 Arch
== _config
->Find("APT::Architecture"))
223 return SingleArchFindPkg(Name
);
225 return PkgIterator(*this,0);
227 /* We make a detour via the GrpIterator here as
228 on a multi-arch environment a group is easier to
229 find than a package (less entries in the buckets) */
230 pkgCache::GrpIterator Grp
= FindGrp(Name
);
231 if (Grp
.end() == true)
232 return PkgIterator(*this,0);
234 return Grp
.FindPkg(Arch
);
237 // Cache::FindGrp - Locate a group by name /*{{{*/
238 // ---------------------------------------------------------------------
239 /* Returns End-Pointer on error, pointer to the group otherwise */
240 pkgCache::GrpIterator
pkgCache::FindGrp(const string
&Name
) {
241 if (unlikely(Name
.empty() == true))
242 return GrpIterator(*this,0);
244 // Look at the hash bucket for the group
245 Group
*Grp
= GrpP
+ HeaderP
->GrpHashTable
[sHash(Name
)];
246 for (; Grp
!= GrpP
; Grp
= GrpP
+ Grp
->Next
) {
247 if (Grp
->Name
!= 0 && StrP
[Grp
->Name
] == Name
[0] &&
248 stringcasecmp(Name
, StrP
+ Grp
->Name
) == 0)
249 return GrpIterator(*this, Grp
);
252 return GrpIterator(*this,0);
255 // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
256 // ---------------------------------------------------------------------
257 /* This returns a string representation of the dependency compare
258 type in the weird debian style.. */
259 const char *pkgCache::CompTypeDeb(unsigned char Comp
)
261 const char *Ops
[] = {"","<=",">=","<<",">>","=","!="};
262 if ((unsigned)(Comp
& 0xF) < 7)
263 return Ops
[Comp
& 0xF];
267 // Cache::CompType - Return a string describing the compare type /*{{{*/
268 // ---------------------------------------------------------------------
269 /* This returns a string representation of the dependency compare
271 const char *pkgCache::CompType(unsigned char Comp
)
273 const char *Ops
[] = {"","<=",">=","<",">","=","!="};
274 if ((unsigned)(Comp
& 0xF) < 7)
275 return Ops
[Comp
& 0xF];
279 // Cache::DepType - Return a string describing the dep type /*{{{*/
280 // ---------------------------------------------------------------------
282 const char *pkgCache::DepType(unsigned char Type
)
284 const char *Types
[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
285 _("Recommends"),_("Conflicts"),_("Replaces"),
286 _("Obsoletes"),_("Breaks"), _("Enhances")};
287 if (Type
< sizeof(Types
)/sizeof(*Types
))
292 // Cache::Priority - Convert a priority value to a string /*{{{*/
293 // ---------------------------------------------------------------------
295 const char *pkgCache::Priority(unsigned char Prio
)
297 const char *Mapping
[] = {0,_("important"),_("required"),_("standard"),
298 _("optional"),_("extra")};
299 if (Prio
< _count(Mapping
))
300 return Mapping
[Prio
];
304 // GrpIterator::FindPkg - Locate a package by arch /*{{{*/
305 // ---------------------------------------------------------------------
306 /* Returns an End-Pointer on error, pointer to the package otherwise */
307 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPkg(string Arch
) {
308 if (unlikely(IsGood() == false || S
->FirstPackage
== 0))
309 return PkgIterator(*Owner
, 0);
311 static string
const myArch
= _config
->Find("APT::Architecture");
312 /* Most of the time the package for our native architecture is
313 the one we add at first to the cache, but this would be the
314 last one we check, so we do it now. */
315 if (Arch
== "native" || Arch
== myArch
) {
317 pkgCache::Package
*Pkg
= Owner
->PkgP
+ S
->LastPackage
;
318 if (stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
319 return PkgIterator(*Owner
, Pkg
);
322 /* If we accept any package we simply return the "first"
323 package in this group (the last one added). */
325 return PkgIterator(*Owner
, Owner
->PkgP
+ S
->FirstPackage
);
327 /* Iterate over the list to find the matching arch
328 unfortunately this list includes "package noise"
329 (= different packages with same calculated hash),
330 so we need to check the name also */
331 for (pkgCache::Package
*Pkg
= PackageList(); Pkg
!= Owner
->PkgP
;
332 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
333 if (S
->Name
== Pkg
->Name
&&
334 stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
335 return PkgIterator(*Owner
, Pkg
);
336 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
340 return PkgIterator(*Owner
, 0);
343 // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
344 // ---------------------------------------------------------------------
345 /* Returns an End-Pointer on error, pointer to the package otherwise.
346 We can't simply ++ to the next as the next package of the last will
347 be from a different group (with the same hash value) */
348 pkgCache::PkgIterator
pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator
const &LastPkg
) {
349 if (unlikely(IsGood() == false || S
->FirstPackage
== 0 ||
350 LastPkg
.end() == true))
351 return PkgIterator(*Owner
, 0);
353 if (S
->LastPackage
== LastPkg
.Index())
354 return PkgIterator(*Owner
, 0);
356 return PkgIterator(*Owner
, Owner
->PkgP
+ LastPkg
->NextPackage
);
359 // GrpIterator::operator ++ - Postfix incr /*{{{*/
360 // ---------------------------------------------------------------------
361 /* This will advance to the next logical group in the hash table. */
362 void pkgCache::GrpIterator::operator ++(int)
364 // Follow the current links
365 if (S
!= Owner
->GrpP
)
366 S
= Owner
->GrpP
+ S
->Next
;
368 // Follow the hash table
369 while (S
== Owner
->GrpP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->GrpHashTable
))
372 S
= Owner
->GrpP
+ Owner
->HeaderP
->GrpHashTable
[HashIndex
];
376 // PkgIterator::operator ++ - Postfix incr /*{{{*/
377 // ---------------------------------------------------------------------
378 /* This will advance to the next logical package in the hash table. */
379 void pkgCache::PkgIterator::operator ++(int)
381 // Follow the current links
382 if (S
!= Owner
->PkgP
)
383 S
= Owner
->PkgP
+ S
->NextPackage
;
385 // Follow the hash table
386 while (S
== Owner
->PkgP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->PkgHashTable
))
389 S
= Owner
->PkgP
+ Owner
->HeaderP
->PkgHashTable
[HashIndex
];
393 // PkgIterator::State - Check the State of the package /*{{{*/
394 // ---------------------------------------------------------------------
395 /* By this we mean if it is either cleanly installed or cleanly removed. */
396 pkgCache::PkgIterator::OkState
pkgCache::PkgIterator::State() const
398 if (S
->InstState
== pkgCache::State::ReInstReq
||
399 S
->InstState
== pkgCache::State::HoldReInstReq
)
402 if (S
->CurrentState
== pkgCache::State::UnPacked
||
403 S
->CurrentState
== pkgCache::State::HalfConfigured
)
404 // we leave triggers alone complettely. dpkg deals with
405 // them in a hard-to-predict manner and if they get
406 // resolved by dpkg before apt run dpkg --configure on
407 // the TriggersPending package dpkg returns a error
408 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
409 //Pkg->CurrentState == pkgCache::State::TriggersPending)
410 return NeedsConfigure
;
412 if (S
->CurrentState
== pkgCache::State::HalfInstalled
||
413 S
->InstState
!= pkgCache::State::Ok
)
419 // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
420 // ---------------------------------------------------------------------
421 /* Return string representing of the candidate version. */
423 pkgCache::PkgIterator::CandVersion() const
425 //TargetVer is empty, so don't use it.
426 VerIterator version
= pkgPolicy(Owner
).GetCandidateVer(*this);
427 if (version
.IsGood())
428 return version
.VerStr();
432 // PkgIterator::CurVersion - Returns the current version string /*{{{*/
433 // ---------------------------------------------------------------------
434 /* Return string representing of the current version. */
436 pkgCache::PkgIterator::CurVersion() const
438 VerIterator version
= CurrentVer();
439 if (version
.IsGood())
440 return CurrentVer().VerStr();
444 // ostream operator to handle string representation of a package /*{{{*/
445 // ---------------------------------------------------------------------
446 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
447 Note that the characters <|>() are all literal above. Versions will be ommited
448 if they provide no new information (e.g. there is no newer version than candidate)
449 If no version and/or section can be found "none" is used. */
451 operator<<(ostream
& out
, pkgCache::PkgIterator Pkg
)
453 if (Pkg
.end() == true)
454 return out
<< "invalid package";
456 string current
= string(Pkg
.CurVersion() == 0 ? "none" : Pkg
.CurVersion());
457 string candidate
= string(Pkg
.CandVersion() == 0 ? "none" : Pkg
.CandVersion());
458 string newest
= string(Pkg
.VersionList().end() ? "none" : Pkg
.VersionList().VerStr());
460 out
<< Pkg
.Name() << " [ " << Pkg
.Arch() << " ] < " << current
;
461 if (current
!= candidate
)
462 out
<< " -> " << candidate
;
463 if ( newest
!= "none" && candidate
!= newest
)
464 out
<< " | " << newest
;
465 out
<< " > ( " << string(Pkg
.Section()==0?"none":Pkg
.Section()) << " )";
469 // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/
470 // ---------------------------------------------------------------------
471 /* Returns a name:arch string */
472 std::string
pkgCache::PkgIterator::FullName(bool const &Pretty
) const
474 string fullname
= Name();
475 if (Pretty
== false ||
476 (strcmp(Arch(), "all") != 0 && _config
->Find("APT::Architecture") != Arch()))
477 return fullname
.append(":").append(Arch());
481 // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
482 // ---------------------------------------------------------------------
483 /* Currently critical deps are defined as depends, predepends and
484 conflicts (including dpkg's Breaks fields). */
485 bool pkgCache::DepIterator::IsCritical()
487 if (S
->Type
== pkgCache::Dep::Conflicts
||
488 S
->Type
== pkgCache::Dep::DpkgBreaks
||
489 S
->Type
== pkgCache::Dep::Obsoletes
||
490 S
->Type
== pkgCache::Dep::Depends
||
491 S
->Type
== pkgCache::Dep::PreDepends
)
496 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
497 // ---------------------------------------------------------------------
498 /* This intellegently looks at dep target packages and tries to figure
499 out which package should be used. This is needed to nicely handle
500 provide mapping. If the target package has no other providing packages
501 then it returned. Otherwise the providing list is looked at to
502 see if there is one one unique providing package if so it is returned.
503 Otherwise true is returned and the target package is set. The return
504 result indicates whether the node should be expandable
506 In Conjunction with the DepCache the value of Result may not be
507 super-good since the policy may have made it uninstallable. Using
508 AllTargets is better in this case. */
509 bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator
&Result
)
511 Result
= TargetPkg();
513 // No provides at all
514 if (Result
->ProvidesList
== 0)
517 // There is the Base package and the providing ones which is at least 2
518 if (Result
->VersionList
!= 0)
521 /* We have to skip over indirect provisions of the package that
522 owns the dependency. For instance, if libc5-dev depends on the
523 virtual package libc-dev which is provided by libc5-dev and libc6-dev
524 we must ignore libc5-dev when considering the provides list. */
525 PrvIterator PStart
= Result
.ProvidesList();
526 for (; PStart
.end() != true && PStart
.OwnerPkg() == ParentPkg(); PStart
++);
528 // Nothing but indirect self provides
529 if (PStart
.end() == true)
532 // Check for single packages in the provides list
533 PrvIterator P
= PStart
;
534 for (; P
.end() != true; P
++)
536 // Skip over self provides
537 if (P
.OwnerPkg() == ParentPkg())
539 if (PStart
.OwnerPkg() != P
.OwnerPkg())
543 Result
= PStart
.OwnerPkg();
545 // Check for non dups
552 // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
553 // ---------------------------------------------------------------------
554 /* This is a more useful version of TargetPkg() that follows versioned
555 provides. It includes every possible package-version that could satisfy
556 the dependency. The last item in the list has a 0. The resulting pointer
557 must be delete [] 'd */
558 pkgCache::Version
**pkgCache::DepIterator::AllTargets()
561 unsigned long Size
=0;
565 PkgIterator DPkg
= TargetPkg();
567 // Walk along the actual package providing versions
568 for (VerIterator I
= DPkg
.VersionList(); I
.end() == false; I
++)
570 if (Owner
->VS
->CheckDep(I
.VerStr(),S
->CompareOp
,TargetVer()) == false)
573 if ((S
->Type
== pkgCache::Dep::Conflicts
||
574 S
->Type
== pkgCache::Dep::DpkgBreaks
||
575 S
->Type
== pkgCache::Dep::Obsoletes
) &&
576 ParentPkg() == I
.ParentPkg())
584 // Follow all provides
585 for (PrvIterator I
= DPkg
.ProvidesList(); I
.end() == false; I
++)
587 if (Owner
->VS
->CheckDep(I
.ProvideVersion(),S
->CompareOp
,TargetVer()) == false)
590 if ((S
->Type
== pkgCache::Dep::Conflicts
||
591 S
->Type
== pkgCache::Dep::DpkgBreaks
||
592 S
->Type
== pkgCache::Dep::Obsoletes
) &&
593 ParentPkg() == I
.OwnerPkg())
598 *End
++ = I
.OwnerVer();
601 // Do it again and write it into the array
604 Res
= new Version
*[Size
+1];
617 // DepIterator::GlobOr - Compute an OR group /*{{{*/
618 // ---------------------------------------------------------------------
619 /* This Takes an iterator, iterates past the current dependency grouping
620 and returns Start and End so that so End is the final element
621 in the group, if End == Start then D is End++ and End is the
622 dependency D was pointing to. Use in loops to iterate sensibly. */
623 void pkgCache::DepIterator::GlobOr(DepIterator
&Start
,DepIterator
&End
)
625 // Compute a single dependency element (glob or)
628 for (bool LastOR
= true; end() == false && LastOR
== true;)
630 LastOR
= (S
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
637 // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
638 // ---------------------------------------------------------------------
639 /* This just looks over the version list to see if B is listed before A. In
640 most cases this will return in under 4 checks, ver lists are short. */
641 int pkgCache::VerIterator::CompareVer(const VerIterator
&B
) const
643 // Check if they are equal
651 /* Start at A and look for B. If B is found then A > B otherwise
652 B was before A so A < B */
653 VerIterator I
= *this;
654 for (;I
.end() == false; I
++)
660 // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
661 // ---------------------------------------------------------------------
663 bool pkgCache::VerIterator::Downloadable() const
665 VerFileIterator Files
= FileList();
666 for (; Files
.end() == false; Files
++)
667 if ((Files
.File()->Flags
& pkgCache::Flag::NotSource
) != pkgCache::Flag::NotSource
)
672 // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
673 // ---------------------------------------------------------------------
674 /* This checks to see if any of the versions files are not NotAutomatic.
675 True if this version is selectable for automatic installation. */
676 bool pkgCache::VerIterator::Automatic() const
678 VerFileIterator Files
= FileList();
679 for (; Files
.end() == false; Files
++)
680 if ((Files
.File()->Flags
& pkgCache::Flag::NotAutomatic
) != pkgCache::Flag::NotAutomatic
)
685 // VerIterator::Pseudo - Check if this version is a pseudo one /*{{{*/
686 // ---------------------------------------------------------------------
687 /* Sometimes you have the need to express dependencies with versions
688 which doesn't really exist or exist multiply times for "different"
689 packages. We need these versions for dependency resolution but they
690 are a problem everytime we need to download/install something. */
691 bool pkgCache::VerIterator::Pseudo() const
693 if (S
->MultiArch
== pkgCache::Version::All
&&
694 strcmp(Arch(true),"all") != 0)
696 GrpIterator
const Grp
= ParentPkg().Group();
697 return (Grp
->LastPackage
!= Grp
->FirstPackage
);
702 // VerIterator::NewestFile - Return the newest file version relation /*{{{*/
703 // ---------------------------------------------------------------------
704 /* This looks at the version numbers associated with all of the sources
705 this version is in and returns the highest.*/
706 pkgCache::VerFileIterator
pkgCache::VerIterator::NewestFile() const
708 VerFileIterator Files
= FileList();
709 VerFileIterator Highest
= Files
;
710 for (; Files
.end() == false; Files
++)
712 if (Owner
->VS
->CmpReleaseVer(Files
.File().Version(),Highest
.File().Version()) > 0)
719 // VerIterator::RelStr - Release description string /*{{{*/
720 // ---------------------------------------------------------------------
721 /* This describes the version from a release-centric manner. The output is a
722 list of Label:Version/Archive */
723 string
pkgCache::VerIterator::RelStr()
727 for (pkgCache::VerFileIterator I
= this->FileList(); I
.end() == false; I
++)
729 // Do not print 'not source' entries'
730 pkgCache::PkgFileIterator File
= I
.File();
731 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
734 // See if we have already printed this out..
736 for (pkgCache::VerFileIterator J
= this->FileList(); I
!= J
; J
++)
738 pkgCache::PkgFileIterator File2
= J
.File();
739 if (File2
->Label
== 0 || File
->Label
== 0)
742 if (strcmp(File
.Label(),File2
.Label()) != 0)
745 if (File2
->Version
== File
->Version
)
750 if (File2
->Version
== 0 || File
->Version
== 0)
752 if (strcmp(File
.Version(),File2
.Version()) == 0)
764 if (File
->Label
!= 0)
765 Res
= Res
+ File
.Label() + ':';
767 if (File
->Archive
!= 0)
769 if (File
->Version
== 0)
770 Res
+= File
.Archive();
772 Res
= Res
+ File
.Version() + '/' + File
.Archive();
776 // No release file, print the host name that this came from
777 if (File
->Site
== 0 || File
.Site()[0] == 0)
783 if (S
->ParentPkg
!= 0)
784 Res
.append(" [").append(Arch()).append("]");
788 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
789 // ---------------------------------------------------------------------
790 /* This stats the file and compares its stats with the ones that were
791 stored during generation. Date checks should probably also be
793 bool pkgCache::PkgFileIterator::IsOk()
796 if (stat(FileName(),&Buf
) != 0)
799 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
805 // PkgFileIterator::RelStr - Return the release string /*{{{*/
806 // ---------------------------------------------------------------------
808 string
pkgCache::PkgFileIterator::RelStr()
812 Res
= Res
+ (Res
.empty() == true?"v=":",v=") + Version();
814 Res
= Res
+ (Res
.empty() == true?"o=":",o=") + Origin();
816 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Archive();
818 Res
= Res
+ (Res
.empty() == true?"n=":",n=") + Codename();
820 Res
= Res
+ (Res
.empty() == true?"l=":",l=") + Label();
821 if (Component() != 0)
822 Res
= Res
+ (Res
.empty() == true?"c=":",c=") + Component();
823 if (Architecture() != 0)
824 Res
= Res
+ (Res
.empty() == true?"b=":",b=") + Architecture();
828 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
829 // ---------------------------------------------------------------------
830 /* return a DescIter for the current locale or the default if none is
833 pkgCache::DescIterator
pkgCache::VerIterator::TranslatedDescription() const
835 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
836 for (std::vector
<string
>::const_iterator l
= lang
.begin();
837 l
!= lang
.end(); l
++)
839 pkgCache::DescIterator DescDefault
= DescriptionList();
840 pkgCache::DescIterator Desc
= DescDefault
;
842 for (; Desc
.end() == false; Desc
++)
843 if (*l
== Desc
.LanguageCode())
845 if (Desc
.end() == true)
850 return DescriptionList();