]>
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
)
115 // Cache::ReMap - Reopen the cache file /*{{{*/
116 // ---------------------------------------------------------------------
117 /* If the file is already closed then this will open it open it. */
118 bool pkgCache::ReMap()
120 // Apply the typecasts.
121 HeaderP
= (Header
*)Map
.Data();
122 GrpP
= (Group
*)Map
.Data();
123 PkgP
= (Package
*)Map
.Data();
124 VerFileP
= (VerFile
*)Map
.Data();
125 DescFileP
= (DescFile
*)Map
.Data();
126 PkgFileP
= (PackageFile
*)Map
.Data();
127 VerP
= (Version
*)Map
.Data();
128 DescP
= (Description
*)Map
.Data();
129 ProvideP
= (Provides
*)Map
.Data();
130 DepP
= (Dependency
*)Map
.Data();
131 StringItemP
= (StringItem
*)Map
.Data();
132 StrP
= (char *)Map
.Data();
134 if (Map
.Size() == 0 || HeaderP
== 0)
135 return _error
->Error(_("Empty package cache"));
139 if (HeaderP
->Signature
!= DefHeader
.Signature
||
140 HeaderP
->Dirty
== true)
141 return _error
->Error(_("The package cache file is corrupted"));
143 if (HeaderP
->MajorVersion
!= DefHeader
.MajorVersion
||
144 HeaderP
->MinorVersion
!= DefHeader
.MinorVersion
||
145 HeaderP
->CheckSizes(DefHeader
) == false)
146 return _error
->Error(_("The package cache file is an incompatible version"));
149 if (HeaderP
->VerSysName
== 0 ||
150 (VS
= pkgVersioningSystem::GetVS(StrP
+ HeaderP
->VerSysName
)) == 0)
151 return _error
->Error(_("This APT does not support the versioning system '%s'"),StrP
+ HeaderP
->VerSysName
);
153 // Chcek the arhcitecture
154 if (HeaderP
->Architecture
== 0 ||
155 _config
->Find("APT::Architecture") != StrP
+ HeaderP
->Architecture
)
156 return _error
->Error(_("The package cache was built for a different architecture"));
160 // Cache::Hash - Hash a string /*{{{*/
161 // ---------------------------------------------------------------------
162 /* This is used to generate the hash entries for the HashTable. With my
163 package list from bo this function gets 94% table usage on a 512 item
164 table (480 used items) */
165 unsigned long pkgCache::sHash(const string
&Str
) const
167 unsigned long Hash
= 0;
168 for (string::const_iterator I
= Str
.begin(); I
!= Str
.end(); I
++)
169 Hash
= 5*Hash
+ tolower_ascii(*I
);
170 return Hash
% _count(HeaderP
->PkgHashTable
);
173 unsigned long pkgCache::sHash(const char *Str
) const
175 unsigned long Hash
= 0;
176 for (const char *I
= Str
; *I
!= 0; I
++)
177 Hash
= 5*Hash
+ tolower_ascii(*I
);
178 return Hash
% _count(HeaderP
->PkgHashTable
);
182 // Cache::FindPkg - Locate a package by name /*{{{*/
183 // ---------------------------------------------------------------------
184 /* Returns 0 on error, pointer to the package otherwise */
185 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
) {
186 size_t const found
= Name
.find(':');
187 if (found
== string::npos
)
188 return FindPkg(Name
, "native");
189 string
const Arch
= Name
.substr(found
+1);
191 return FindPkg(Name
, "any");
192 return FindPkg(Name
.substr(0, found
), Arch
);
195 // Cache::FindPkg - Locate a package by name /*{{{*/
196 // ---------------------------------------------------------------------
197 /* Returns 0 on error, pointer to the package otherwise */
198 pkgCache::PkgIterator
pkgCache::FindPkg(const string
&Name
, string Arch
) {
199 /* We make a detour via the GrpIterator here as
200 on a multi-arch environment a group is easier to
201 find than a package (less entries in the buckets) */
202 pkgCache::GrpIterator Grp
= FindGrp(Name
);
203 if (Grp
.end() == true)
204 return PkgIterator(*this,0);
206 return Grp
.FindPkg(Arch
);
209 // Cache::FindGrp - Locate a group by name /*{{{*/
210 // ---------------------------------------------------------------------
211 /* Returns End-Pointer on error, pointer to the group otherwise */
212 pkgCache::GrpIterator
pkgCache::FindGrp(const string
&Name
) {
213 if (unlikely(Name
.empty() == true))
214 return GrpIterator(*this,0);
216 // Look at the hash bucket for the group
217 Group
*Grp
= GrpP
+ HeaderP
->GrpHashTable
[sHash(Name
)];
218 for (; Grp
!= GrpP
; Grp
= GrpP
+ Grp
->Next
) {
219 if (Grp
->Name
!= 0 && StrP
[Grp
->Name
] == Name
[0] &&
220 stringcasecmp(Name
, StrP
+ Grp
->Name
) == 0)
221 return GrpIterator(*this, Grp
);
224 return GrpIterator(*this,0);
227 // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
228 // ---------------------------------------------------------------------
229 /* This returns a string representation of the dependency compare
230 type in the weird debian style.. */
231 const char *pkgCache::CompTypeDeb(unsigned char Comp
)
233 const char *Ops
[] = {"","<=",">=","<<",">>","=","!="};
234 if ((unsigned)(Comp
& 0xF) < 7)
235 return Ops
[Comp
& 0xF];
239 // Cache::CompType - Return a string describing the compare type /*{{{*/
240 // ---------------------------------------------------------------------
241 /* This returns a string representation of the dependency compare
243 const char *pkgCache::CompType(unsigned char Comp
)
245 const char *Ops
[] = {"","<=",">=","<",">","=","!="};
246 if ((unsigned)(Comp
& 0xF) < 7)
247 return Ops
[Comp
& 0xF];
251 // Cache::DepType - Return a string describing the dep type /*{{{*/
252 // ---------------------------------------------------------------------
254 const char *pkgCache::DepType(unsigned char Type
)
256 const char *Types
[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
257 _("Recommends"),_("Conflicts"),_("Replaces"),
258 _("Obsoletes"),_("Breaks"), _("Enhances")};
259 if (Type
< sizeof(Types
)/sizeof(*Types
))
264 // Cache::Priority - Convert a priority value to a string /*{{{*/
265 // ---------------------------------------------------------------------
267 const char *pkgCache::Priority(unsigned char Prio
)
269 const char *Mapping
[] = {0,_("important"),_("required"),_("standard"),
270 _("optional"),_("extra")};
271 if (Prio
< _count(Mapping
))
272 return Mapping
[Prio
];
276 // GrpIterator::FindPkg - Locate a package by arch /*{{{*/
277 // ---------------------------------------------------------------------
278 /* Returns an End-Pointer on error, pointer to the package otherwise */
279 pkgCache::PkgIterator
pkgCache::GrpIterator::FindPkg(string Arch
) {
280 if (unlikely(IsGood() == false || S
->FirstPackage
== 0))
281 return PkgIterator(*Owner
, 0);
283 static string
const myArch
= _config
->Find("APT::Architecture");
284 /* Most of the time the package for our native architecture is
285 the one we add at first to the cache, but this would be the
286 last one we check, so we do it now. */
287 if (Arch
== "native" || Arch
== myArch
) {
289 pkgCache::Package
*Pkg
= Owner
->PkgP
+ S
->LastPackage
;
290 if (stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
291 return PkgIterator(*Owner
, Pkg
);
294 /* If we accept any package we simply return the "first"
295 package in this group (the last one added). */
297 return PkgIterator(*Owner
, Owner
->PkgP
+ S
->FirstPackage
);
299 /* Iterate over the list to find the matching arch
300 unfortunately this list includes "package noise"
301 (= different packages with same calculated hash),
302 so we need to check the name also */
303 for (pkgCache::Package
*Pkg
= PackageList(); Pkg
!= Owner
->PkgP
;
304 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
305 if (S
->Name
== Pkg
->Name
&&
306 stringcasecmp(Arch
, Owner
->StrP
+ Pkg
->Arch
) == 0)
307 return PkgIterator(*Owner
, Pkg
);
308 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
312 return PkgIterator(*Owner
, 0);
315 // GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
316 // ---------------------------------------------------------------------
317 /* Returns an End-Pointer on error, pointer to the package otherwise.
318 We can't simply ++ to the next as the list of packages includes
319 "package noise" (= packages with the same hash value but different name) */
320 pkgCache::PkgIterator
pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator
const &LastPkg
) {
321 if (unlikely(IsGood() == false || S
->FirstPackage
== 0 ||
322 LastPkg
.end() == true))
323 return PkgIterator(*Owner
, 0);
325 // Iterate over the list to find the next package
326 pkgCache::Package
*Pkg
= Owner
->PkgP
+ LastPkg
.Index();
327 Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
;
328 for (; Pkg
!= Owner
->PkgP
; Pkg
= Owner
->PkgP
+ Pkg
->NextPackage
) {
329 if (S
->Name
== Pkg
->Name
)
330 return PkgIterator(*Owner
, Pkg
);
331 if ((Owner
->PkgP
+ S
->LastPackage
) == Pkg
)
335 return PkgIterator(*Owner
, 0);
338 // GrpIterator::operator ++ - Postfix incr /*{{{*/
339 // ---------------------------------------------------------------------
340 /* This will advance to the next logical group in the hash table. */
341 void pkgCache::GrpIterator::operator ++(int)
343 // Follow the current links
344 if (S
!= Owner
->GrpP
)
345 S
= Owner
->GrpP
+ S
->Next
;
347 // Follow the hash table
348 while (S
== Owner
->GrpP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->GrpHashTable
))
351 S
= Owner
->GrpP
+ Owner
->HeaderP
->GrpHashTable
[HashIndex
];
355 // PkgIterator::operator ++ - Postfix incr /*{{{*/
356 // ---------------------------------------------------------------------
357 /* This will advance to the next logical package in the hash table. */
358 void pkgCache::PkgIterator::operator ++(int)
360 // Follow the current links
361 if (S
!= Owner
->PkgP
)
362 S
= Owner
->PkgP
+ S
->NextPackage
;
364 // Follow the hash table
365 while (S
== Owner
->PkgP
&& (HashIndex
+1) < (signed)_count(Owner
->HeaderP
->PkgHashTable
))
368 S
= Owner
->PkgP
+ Owner
->HeaderP
->PkgHashTable
[HashIndex
];
372 // PkgIterator::State - Check the State of the package /*{{{*/
373 // ---------------------------------------------------------------------
374 /* By this we mean if it is either cleanly installed or cleanly removed. */
375 pkgCache::PkgIterator::OkState
pkgCache::PkgIterator::State() const
377 if (S
->InstState
== pkgCache::State::ReInstReq
||
378 S
->InstState
== pkgCache::State::HoldReInstReq
)
381 if (S
->CurrentState
== pkgCache::State::UnPacked
||
382 S
->CurrentState
== pkgCache::State::HalfConfigured
)
383 // we leave triggers alone complettely. dpkg deals with
384 // them in a hard-to-predict manner and if they get
385 // resolved by dpkg before apt run dpkg --configure on
386 // the TriggersPending package dpkg returns a error
387 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
388 //Pkg->CurrentState == pkgCache::State::TriggersPending)
389 return NeedsConfigure
;
391 if (S
->CurrentState
== pkgCache::State::HalfInstalled
||
392 S
->InstState
!= pkgCache::State::Ok
)
398 // PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
399 // ---------------------------------------------------------------------
400 /* Return string representing of the candidate version. */
402 pkgCache::PkgIterator::CandVersion() const
404 //TargetVer is empty, so don't use it.
405 VerIterator version
= pkgPolicy(Owner
).GetCandidateVer(*this);
406 if (version
.IsGood())
407 return version
.VerStr();
411 // PkgIterator::CurVersion - Returns the current version string /*{{{*/
412 // ---------------------------------------------------------------------
413 /* Return string representing of the current version. */
415 pkgCache::PkgIterator::CurVersion() const
417 VerIterator version
= CurrentVer();
418 if (version
.IsGood())
419 return CurrentVer().VerStr();
423 // ostream operator to handle string representation of a package /*{{{*/
424 // ---------------------------------------------------------------------
425 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
426 Note that the characters <|>() are all literal above. Versions will be ommited
427 if they provide no new information (e.g. there is no newer version than candidate)
428 If no version and/or section can be found "none" is used. */
430 operator<<(ostream
& out
, pkgCache::PkgIterator Pkg
)
432 if (Pkg
.end() == true)
433 return out
<< "invalid package";
435 string current
= string(Pkg
.CurVersion() == 0 ? "none" : Pkg
.CurVersion());
436 string candidate
= string(Pkg
.CandVersion() == 0 ? "none" : Pkg
.CandVersion());
437 string newest
= string(Pkg
.VersionList().end() ? "none" : Pkg
.VersionList().VerStr());
439 out
<< Pkg
.Name() << " [ " << Pkg
.Arch() << " ] < " << current
;
440 if (current
!= candidate
)
441 out
<< " -> " << candidate
;
442 if ( newest
!= "none" && candidate
!= newest
)
443 out
<< " | " << newest
;
444 out
<< " > ( " << string(Pkg
.Section()==0?"none":Pkg
.Section()) << " )";
448 // PkgIterator::FullName - Returns Name and (maybe) Architecture /*{{{*/
449 // ---------------------------------------------------------------------
450 /* Returns a name:arch string */
451 std::string
pkgCache::PkgIterator::FullName(bool const &Pretty
) const
453 string fullname
= Name();
454 if (Pretty
== false ||
455 (strcmp(Arch(), "all") != 0 && _config
->Find("APT::Architecture") != Arch()))
456 return fullname
.append(":").append(Arch());
460 // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
461 // ---------------------------------------------------------------------
462 /* Currently critical deps are defined as depends, predepends and
463 conflicts (including dpkg's Breaks fields). */
464 bool pkgCache::DepIterator::IsCritical()
466 if (S
->Type
== pkgCache::Dep::Conflicts
||
467 S
->Type
== pkgCache::Dep::DpkgBreaks
||
468 S
->Type
== pkgCache::Dep::Obsoletes
||
469 S
->Type
== pkgCache::Dep::Depends
||
470 S
->Type
== pkgCache::Dep::PreDepends
)
475 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
476 // ---------------------------------------------------------------------
477 /* This intellegently looks at dep target packages and tries to figure
478 out which package should be used. This is needed to nicely handle
479 provide mapping. If the target package has no other providing packages
480 then it returned. Otherwise the providing list is looked at to
481 see if there is one one unique providing package if so it is returned.
482 Otherwise true is returned and the target package is set. The return
483 result indicates whether the node should be expandable
485 In Conjunction with the DepCache the value of Result may not be
486 super-good since the policy may have made it uninstallable. Using
487 AllTargets is better in this case. */
488 bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator
&Result
)
490 Result
= TargetPkg();
492 // No provides at all
493 if (Result
->ProvidesList
== 0)
496 // There is the Base package and the providing ones which is at least 2
497 if (Result
->VersionList
!= 0)
500 /* We have to skip over indirect provisions of the package that
501 owns the dependency. For instance, if libc5-dev depends on the
502 virtual package libc-dev which is provided by libc5-dev and libc6-dev
503 we must ignore libc5-dev when considering the provides list. */
504 PrvIterator PStart
= Result
.ProvidesList();
505 for (; PStart
.end() != true && PStart
.OwnerPkg() == ParentPkg(); PStart
++);
507 // Nothing but indirect self provides
508 if (PStart
.end() == true)
511 // Check for single packages in the provides list
512 PrvIterator P
= PStart
;
513 for (; P
.end() != true; P
++)
515 // Skip over self provides
516 if (P
.OwnerPkg() == ParentPkg())
518 if (PStart
.OwnerPkg() != P
.OwnerPkg())
522 Result
= PStart
.OwnerPkg();
524 // Check for non dups
531 // DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
532 // ---------------------------------------------------------------------
533 /* This is a more useful version of TargetPkg() that follows versioned
534 provides. It includes every possible package-version that could satisfy
535 the dependency. The last item in the list has a 0. The resulting pointer
536 must be delete [] 'd */
537 pkgCache::Version
**pkgCache::DepIterator::AllTargets()
540 unsigned long Size
=0;
544 PkgIterator DPkg
= TargetPkg();
546 // Walk along the actual package providing versions
547 for (VerIterator I
= DPkg
.VersionList(); I
.end() == false; I
++)
549 if (Owner
->VS
->CheckDep(I
.VerStr(),S
->CompareOp
,TargetVer()) == false)
552 if ((S
->Type
== pkgCache::Dep::Conflicts
||
553 S
->Type
== pkgCache::Dep::DpkgBreaks
||
554 S
->Type
== pkgCache::Dep::Obsoletes
) &&
555 ParentPkg() == I
.ParentPkg())
563 // Follow all provides
564 for (PrvIterator I
= DPkg
.ProvidesList(); I
.end() == false; I
++)
566 if (Owner
->VS
->CheckDep(I
.ProvideVersion(),S
->CompareOp
,TargetVer()) == false)
569 if ((S
->Type
== pkgCache::Dep::Conflicts
||
570 S
->Type
== pkgCache::Dep::DpkgBreaks
||
571 S
->Type
== pkgCache::Dep::Obsoletes
) &&
572 ParentPkg() == I
.OwnerPkg())
577 *End
++ = I
.OwnerVer();
580 // Do it again and write it into the array
583 Res
= new Version
*[Size
+1];
596 // DepIterator::GlobOr - Compute an OR group /*{{{*/
597 // ---------------------------------------------------------------------
598 /* This Takes an iterator, iterates past the current dependency grouping
599 and returns Start and End so that so End is the final element
600 in the group, if End == Start then D is End++ and End is the
601 dependency D was pointing to. Use in loops to iterate sensibly. */
602 void pkgCache::DepIterator::GlobOr(DepIterator
&Start
,DepIterator
&End
)
604 // Compute a single dependency element (glob or)
607 for (bool LastOR
= true; end() == false && LastOR
== true;)
609 LastOR
= (S
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
616 // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
617 // ---------------------------------------------------------------------
618 /* This just looks over the version list to see if B is listed before A. In
619 most cases this will return in under 4 checks, ver lists are short. */
620 int pkgCache::VerIterator::CompareVer(const VerIterator
&B
) const
622 // Check if they are equal
630 /* Start at A and look for B. If B is found then A > B otherwise
631 B was before A so A < B */
632 VerIterator I
= *this;
633 for (;I
.end() == false; I
++)
639 // VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
640 // ---------------------------------------------------------------------
642 bool pkgCache::VerIterator::Downloadable() const
644 VerFileIterator Files
= FileList();
645 for (; Files
.end() == false; Files
++)
646 if ((Files
.File()->Flags
& pkgCache::Flag::NotSource
) != pkgCache::Flag::NotSource
)
651 // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
652 // ---------------------------------------------------------------------
653 /* This checks to see if any of the versions files are not NotAutomatic.
654 True if this version is selectable for automatic installation. */
655 bool pkgCache::VerIterator::Automatic() const
657 VerFileIterator Files
= FileList();
658 for (; Files
.end() == false; Files
++)
659 if ((Files
.File()->Flags
& pkgCache::Flag::NotAutomatic
) != pkgCache::Flag::NotAutomatic
)
664 // VerIterator::Pseudo - Check if this version is a pseudo one /*{{{*/
665 // ---------------------------------------------------------------------
666 /* Sometimes you have the need to express dependencies with versions
667 which doesn't really exist or exist multiply times for "different"
668 packages. We need these versions for dependency resolution but they
669 are a problem everytime we need to download/install something. */
670 bool pkgCache::VerIterator::Pseudo() const
672 if (S
->MultiArch
== pkgCache::Version::All
&&
673 strcmp(Arch(true),"all") != 0)
675 GrpIterator
const Grp
= ParentPkg().Group();
676 return (Grp
->LastPackage
!= Grp
->FirstPackage
);
681 // VerIterator::NewestFile - Return the newest file version relation /*{{{*/
682 // ---------------------------------------------------------------------
683 /* This looks at the version numbers associated with all of the sources
684 this version is in and returns the highest.*/
685 pkgCache::VerFileIterator
pkgCache::VerIterator::NewestFile() const
687 VerFileIterator Files
= FileList();
688 VerFileIterator Highest
= Files
;
689 for (; Files
.end() == false; Files
++)
691 if (Owner
->VS
->CmpReleaseVer(Files
.File().Version(),Highest
.File().Version()) > 0)
698 // VerIterator::RelStr - Release description string /*{{{*/
699 // ---------------------------------------------------------------------
700 /* This describes the version from a release-centric manner. The output is a
701 list of Label:Version/Archive */
702 string
pkgCache::VerIterator::RelStr()
706 for (pkgCache::VerFileIterator I
= this->FileList(); I
.end() == false; I
++)
708 // Do not print 'not source' entries'
709 pkgCache::PkgFileIterator File
= I
.File();
710 if ((File
->Flags
& pkgCache::Flag::NotSource
) == pkgCache::Flag::NotSource
)
713 // See if we have already printed this out..
715 for (pkgCache::VerFileIterator J
= this->FileList(); I
!= J
; J
++)
717 pkgCache::PkgFileIterator File2
= J
.File();
718 if (File2
->Label
== 0 || File
->Label
== 0)
721 if (strcmp(File
.Label(),File2
.Label()) != 0)
724 if (File2
->Version
== File
->Version
)
729 if (File2
->Version
== 0 || File
->Version
== 0)
731 if (strcmp(File
.Version(),File2
.Version()) == 0)
743 if (File
->Label
!= 0)
744 Res
= Res
+ File
.Label() + ':';
746 if (File
->Archive
!= 0)
748 if (File
->Version
== 0)
749 Res
+= File
.Archive();
751 Res
= Res
+ File
.Version() + '/' + File
.Archive();
755 // No release file, print the host name that this came from
756 if (File
->Site
== 0 || File
.Site()[0] == 0)
762 if (S
->ParentPkg
!= 0)
763 Res
.append(" [").append(Arch()).append("]");
767 // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
768 // ---------------------------------------------------------------------
769 /* This stats the file and compares its stats with the ones that were
770 stored during generation. Date checks should probably also be
772 bool pkgCache::PkgFileIterator::IsOk()
775 if (stat(FileName(),&Buf
) != 0)
778 if (Buf
.st_size
!= (signed)S
->Size
|| Buf
.st_mtime
!= S
->mtime
)
784 // PkgFileIterator::RelStr - Return the release string /*{{{*/
785 // ---------------------------------------------------------------------
787 string
pkgCache::PkgFileIterator::RelStr()
791 Res
= Res
+ (Res
.empty() == true?"v=":",v=") + Version();
793 Res
= Res
+ (Res
.empty() == true?"o=":",o=") + Origin();
795 Res
= Res
+ (Res
.empty() == true?"a=":",a=") + Archive();
797 Res
= Res
+ (Res
.empty() == true?"n=":",n=") + Codename();
799 Res
= Res
+ (Res
.empty() == true?"l=":",l=") + Label();
800 if (Component() != 0)
801 Res
= Res
+ (Res
.empty() == true?"c=":",c=") + Component();
802 if (Architecture() != 0)
803 Res
= Res
+ (Res
.empty() == true?"b=":",b=") + Architecture();
807 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
808 // ---------------------------------------------------------------------
809 /* return a DescIter for the current locale or the default if none is
812 pkgCache::DescIterator
pkgCache::VerIterator::TranslatedDescription() const
814 std::vector
<string
> const lang
= APT::Configuration::getLanguages();
815 for (std::vector
<string
>::const_iterator l
= lang
.begin();
816 l
!= lang
.end(); l
++)
818 pkgCache::DescIterator DescDefault
= DescriptionList();
819 pkgCache::DescIterator Desc
= DescDefault
;
821 for (; Desc
.end() == false; Desc
++)
822 if (*l
== Desc
.LanguageCode())
824 if (Desc
.end() == true)
829 return DescriptionList();