]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.cc
* cmdline/apt-get.cc, apt-pkg/cdrom.cc:
[apt.git] / apt-pkg / pkgcache.cc
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
bac2e715 3// $Id: pkgcache.cc,v 1.37 2003/02/10 01:40:58 doogie Exp $
578bfd0a
AL
4/* ######################################################################
5
6 Package Cache - Accessor code for the cache
7
094a497d 8 Please see doc/apt-pkg/cache.sgml for a more detailed description of
578bfd0a
AL
9 this format. Also be sure to keep that file up-to-date!!
10
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.
16
17 The main class provides for ways to get package indexes and some
18 general lookup functions to start the iterators.
19
20 ##################################################################### */
21 /*}}}*/
22// Include Files /*{{{*/
094a497d 23#include <apt-pkg/pkgcache.h>
af29ffb4 24#include <apt-pkg/policy.h>
012b102a 25#include <apt-pkg/indexfile.h>
094a497d
AL
26#include <apt-pkg/version.h>
27#include <apt-pkg/error.h>
231fea14 28#include <apt-pkg/strutl.h>
b2e465d6 29#include <apt-pkg/configuration.h>
578bfd0a 30
b2e465d6
AL
31#include <apti18n.h>
32
578bfd0a
AL
33#include <string>
34#include <sys/stat.h>
35#include <unistd.h>
1ae93c94 36
851a45a8 37#include <ctype.h>
578bfd0a
AL
38 /*}}}*/
39
851a45a8
AL
40using std::string;
41
012b102a 42
578bfd0a
AL
43// Cache::Header::Header - Constructor /*{{{*/
44// ---------------------------------------------------------------------
45/* Simply initialize the header */
46pkgCache::Header::Header()
47{
48 Signature = 0x98FE76DC;
49
50 /* Whenever the structures change the major version should be bumped,
51 whenever the generator changes the minor version should be bumped. */
f8ae7e8b 52 MajorVersion = 8;
6a3da7a6 53 MinorVersion = 0;
b2e465d6 54 Dirty = false;
578bfd0a
AL
55
56 HeaderSz = sizeof(pkgCache::Header);
57 PackageSz = sizeof(pkgCache::Package);
58 PackageFileSz = sizeof(pkgCache::PackageFile);
59 VersionSz = sizeof(pkgCache::Version);
a52f938b 60 DescriptionSz = sizeof(pkgCache::Description);
578bfd0a
AL
61 DependencySz = sizeof(pkgCache::Dependency);
62 ProvidesSz = sizeof(pkgCache::Provides);
dcb79bae 63 VerFileSz = sizeof(pkgCache::VerFile);
a52f938b 64 DescFileSz = sizeof(pkgCache::DescFile);
dcb79bae 65
578bfd0a
AL
66 PackageCount = 0;
67 VersionCount = 0;
a52f938b 68 DescriptionCount = 0;
578bfd0a
AL
69 DependsCount = 0;
70 PackageFileCount = 0;
a7e66b17 71 VerFileCount = 0;
a52f938b 72 DescFileCount = 0;
a7e66b17 73 ProvidesCount = 0;
ad00ae81 74 MaxVerFileSize = 0;
a52f938b 75 MaxDescFileSize = 0;
578bfd0a
AL
76
77 FileList = 0;
78 StringList = 0;
b2e465d6
AL
79 VerSysName = 0;
80 Architecture = 0;
578bfd0a
AL
81 memset(HashTable,0,sizeof(HashTable));
82 memset(Pools,0,sizeof(Pools));
83}
84 /*}}}*/
85// Cache::Header::CheckSizes - Check if the two headers have same *sz /*{{{*/
86// ---------------------------------------------------------------------
87/* */
88bool pkgCache::Header::CheckSizes(Header &Against) const
89{
90 if (HeaderSz == Against.HeaderSz &&
91 PackageSz == Against.PackageSz &&
92 PackageFileSz == Against.PackageFileSz &&
93 VersionSz == Against.VersionSz &&
a52f938b 94 DescriptionSz == Against.DescriptionSz &&
dcb79bae
AL
95 DependencySz == Against.DependencySz &&
96 VerFileSz == Against.VerFileSz &&
a52f938b 97 DescFileSz == Against.DescFileSz &&
578bfd0a
AL
98 ProvidesSz == Against.ProvidesSz)
99 return true;
100 return false;
101}
102 /*}}}*/
103
104// Cache::pkgCache - Constructor /*{{{*/
105// ---------------------------------------------------------------------
106/* */
b2e465d6 107pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map)
578bfd0a 108{
b2e465d6
AL
109 if (DoMap == true)
110 ReMap();
578bfd0a
AL
111}
112 /*}}}*/
113// Cache::ReMap - Reopen the cache file /*{{{*/
114// ---------------------------------------------------------------------
115/* If the file is already closed then this will open it open it. */
116bool pkgCache::ReMap()
117{
118 // Apply the typecasts.
119 HeaderP = (Header *)Map.Data();
120 PkgP = (Package *)Map.Data();
dcb79bae 121 VerFileP = (VerFile *)Map.Data();
a52f938b 122 DescFileP = (DescFile *)Map.Data();
578bfd0a
AL
123 PkgFileP = (PackageFile *)Map.Data();
124 VerP = (Version *)Map.Data();
a52f938b 125 DescP = (Description *)Map.Data();
578bfd0a
AL
126 ProvideP = (Provides *)Map.Data();
127 DepP = (Dependency *)Map.Data();
128 StringItemP = (StringItem *)Map.Data();
129 StrP = (char *)Map.Data();
130
b2e465d6
AL
131 if (Map.Size() == 0 || HeaderP == 0)
132 return _error->Error(_("Empty package cache"));
578bfd0a
AL
133
134 // Check the header
135 Header DefHeader;
136 if (HeaderP->Signature != DefHeader.Signature ||
137 HeaderP->Dirty == true)
b2e465d6 138 return _error->Error(_("The package cache file is corrupted"));
578bfd0a
AL
139
140 if (HeaderP->MajorVersion != DefHeader.MajorVersion ||
141 HeaderP->MinorVersion != DefHeader.MinorVersion ||
142 HeaderP->CheckSizes(DefHeader) == false)
b2e465d6
AL
143 return _error->Error(_("The package cache file is an incompatible version"));
144
145 // Locate our VS..
146 if (HeaderP->VerSysName == 0 ||
147 (VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0)
db0db9fe 148 return _error->Error(_("This APT does not support the versioning system '%s'"),StrP + HeaderP->VerSysName);
b2e465d6
AL
149
150 // Chcek the arhcitecture
151 if (HeaderP->Architecture == 0 ||
152 _config->Find("APT::Architecture") != StrP + HeaderP->Architecture)
bac2e715 153 return _error->Error(_("The package cache was built for a different architecture"));
578bfd0a
AL
154 return true;
155}
156 /*}}}*/
157// Cache::Hash - Hash a string /*{{{*/
158// ---------------------------------------------------------------------
159/* This is used to generate the hash entries for the HashTable. With my
160 package list from bo this function gets 94% table usage on a 512 item
161 table (480 used items) */
171c75f1 162unsigned long pkgCache::sHash(const string &Str) const
578bfd0a
AL
163{
164 unsigned long Hash = 0;
851a45a8 165 for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
4e86942a 166 Hash = 5*Hash + tolower_ascii(*I);
f9eec0e7 167 return Hash % _count(HeaderP->HashTable);
578bfd0a
AL
168}
169
f9eec0e7 170unsigned long pkgCache::sHash(const char *Str) const
578bfd0a
AL
171{
172 unsigned long Hash = 0;
f9eec0e7 173 for (const char *I = Str; *I != 0; I++)
4e86942a 174 Hash = 5*Hash + tolower_ascii(*I);
f9eec0e7 175 return Hash % _count(HeaderP->HashTable);
578bfd0a
AL
176}
177
178 /*}}}*/
179// Cache::FindPkg - Locate a package by name /*{{{*/
180// ---------------------------------------------------------------------
181/* Returns 0 on error, pointer to the package otherwise */
171c75f1 182pkgCache::PkgIterator pkgCache::FindPkg(const string &Name)
578bfd0a
AL
183{
184 // Look at the hash bucket
185 Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)];
186 for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
187 {
c1a22377 188 if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] &&
851a45a8 189 stringcasecmp(Name,StrP + Pkg->Name) == 0)
578bfd0a
AL
190 return PkgIterator(*this,Pkg);
191 }
192 return PkgIterator(*this,0);
193}
194 /*}}}*/
b2e465d6
AL
195// Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/
196// ---------------------------------------------------------------------
197/* This returns a string representation of the dependency compare
198 type in the weird debian style.. */
199const char *pkgCache::CompTypeDeb(unsigned char Comp)
200{
201 const char *Ops[] = {"","<=",">=","<<",">>","=","!="};
202 if ((unsigned)(Comp & 0xF) < 7)
203 return Ops[Comp & 0xF];
204 return "";
205}
206 /*}}}*/
207// Cache::CompType - Return a string describing the compare type /*{{{*/
208// ---------------------------------------------------------------------
209/* This returns a string representation of the dependency compare
210 type */
211const char *pkgCache::CompType(unsigned char Comp)
212{
213 const char *Ops[] = {"","<=",">=","<",">","=","!="};
214 if ((unsigned)(Comp & 0xF) < 7)
215 return Ops[Comp & 0xF];
216 return "";
217}
218 /*}}}*/
219// Cache::DepType - Return a string describing the dep type /*{{{*/
220// ---------------------------------------------------------------------
221/* */
222const char *pkgCache::DepType(unsigned char Type)
223{
224 const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"),
225 _("Recommends"),_("Conflicts"),_("Replaces"),
f8ae7e8b 226 _("Obsoletes"),_("Breaks"), _("Enhances")};
308c7d30 227 if (Type < sizeof(Types)/sizeof(*Types))
b2e465d6
AL
228 return Types[Type];
229 return "";
230}
231 /*}}}*/
0149949b
AL
232// Cache::Priority - Convert a priority value to a string /*{{{*/
233// ---------------------------------------------------------------------
234/* */
235const char *pkgCache::Priority(unsigned char Prio)
236{
b2e465d6
AL
237 const char *Mapping[] = {0,_("important"),_("required"),_("standard"),
238 _("optional"),_("extra")};
0149949b
AL
239 if (Prio < _count(Mapping))
240 return Mapping[Prio];
241 return 0;
242}
243 /*}}}*/
f55a958f
AL
244// Bases for iterator classes /*{{{*/
245void pkgCache::VerIterator::_dummy() {}
246void pkgCache::DepIterator::_dummy() {}
247void pkgCache::PrvIterator::_dummy() {}
770c32ec 248void pkgCache::DescIterator::_dummy() {}
f55a958f
AL
249 /*}}}*/
250// PkgIterator::operator ++ - Postfix incr /*{{{*/
578bfd0a
AL
251// ---------------------------------------------------------------------
252/* This will advance to the next logical package in the hash table. */
253void pkgCache::PkgIterator::operator ++(int)
254{
255 // Follow the current links
256 if (Pkg != Owner->PkgP)
257 Pkg = Owner->PkgP + Pkg->NextPackage;
b2e465d6 258
578bfd0a 259 // Follow the hash table
b2e465d6 260 while (Pkg == Owner->PkgP && (HashIndex+1) < (signed)_count(Owner->HeaderP->HashTable))
578bfd0a
AL
261 {
262 HashIndex++;
263 Pkg = Owner->PkgP + Owner->HeaderP->HashTable[HashIndex];
264 }
265};
266 /*}}}*/
578bfd0a
AL
267// PkgIterator::State - Check the State of the package /*{{{*/
268// ---------------------------------------------------------------------
269/* By this we mean if it is either cleanly installed or cleanly removed. */
270pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
d38b7b3d 271{
c7c1b0f6
AL
272 if (Pkg->InstState == pkgCache::State::ReInstReq ||
273 Pkg->InstState == pkgCache::State::HoldReInstReq)
274 return NeedsUnpack;
275
7d4f285b 276 if (Pkg->CurrentState == pkgCache::State::UnPacked ||
c6aa14e4
MV
277 Pkg->CurrentState == pkgCache::State::HalfConfigured)
278 // we leave triggers alone complettely. dpkg deals with
279 // them in a hard-to-predict manner and if they get
280 // resolved by dpkg before apt run dpkg --configure on
281 // the TriggersPending package dpkg returns a error
09fab244 282 //Pkg->CurrentState == pkgCache::State::TriggersAwaited
c6aa14e4 283 //Pkg->CurrentState == pkgCache::State::TriggersPending)
578bfd0a
AL
284 return NeedsConfigure;
285
a005475e 286 if (Pkg->CurrentState == pkgCache::State::HalfInstalled ||
7d4f285b 287 Pkg->InstState != pkgCache::State::Ok)
578bfd0a
AL
288 return NeedsUnpack;
289
290 return NeedsNothing;
291}
292 /*}}}*/
af29ffb4
MV
293// PkgIterator::CandVersion - Returns the candidate version string /*{{{*/
294// ---------------------------------------------------------------------
295/* Return string representing of the candidate version. */
296const char *
297pkgCache::PkgIterator::CandVersion() const
298{
299 //TargetVer is empty, so don't use it.
46e39c8e 300 VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this);
af29ffb4
MV
301 if (version.IsGood())
302 return version.VerStr();
303 return 0;
304};
305 /*}}}*/
306// PkgIterator::CurVersion - Returns the current version string /*{{{*/
307// ---------------------------------------------------------------------
308/* Return string representing of the current version. */
309const char *
310pkgCache::PkgIterator::CurVersion() const
311{
312 VerIterator version = CurrentVer();
313 if (version.IsGood())
314 return CurrentVer().VerStr();
315 return 0;
316};
317 /*}}}*/
318// ostream operator to handle string representation of a package /*{{{*/
319// ---------------------------------------------------------------------
320/* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
321 Note that the characters <|>() are all literal above. Versions will be ommited
322 if they provide no new information (e.g. there is no newer version than candidate)
323 If no version and/or section can be found "none" is used. */
324std::ostream&
325operator<<(ostream& out, pkgCache::PkgIterator Pkg)
326{
327 if (Pkg.end() == true)
328 return out << "invalid package";
329
330 string current = string(Pkg.CurVersion() == 0 ? "none" : Pkg.CurVersion());
331 string candidate = string(Pkg.CandVersion() == 0 ? "none" : Pkg.CandVersion());
332 string newest = string(Pkg.VersionList().end() ? "none" : Pkg.VersionList().VerStr());
333
334 out << Pkg.Name() << " < " << current;
335 if (current != candidate)
336 out << " -> " << candidate;
337 if ( newest != "none" && candidate != newest)
338 out << " | " << newest;
339 out << " > ( " << string(Pkg.Section()==0?"none":Pkg.Section()) << " )";
340 return out;
341}
342 /*}}}*/
578bfd0a
AL
343// DepIterator::IsCritical - Returns true if the dep is important /*{{{*/
344// ---------------------------------------------------------------------
345/* Currently critical deps are defined as depends, predepends and
308c7d30 346 conflicts (including dpkg's Breaks fields). */
578bfd0a
AL
347bool pkgCache::DepIterator::IsCritical()
348{
b2e465d6 349 if (Dep->Type == pkgCache::Dep::Conflicts ||
308c7d30 350 Dep->Type == pkgCache::Dep::DpkgBreaks ||
b2e465d6 351 Dep->Type == pkgCache::Dep::Obsoletes ||
f07b5628
AL
352 Dep->Type == pkgCache::Dep::Depends ||
353 Dep->Type == pkgCache::Dep::PreDepends)
578bfd0a
AL
354 return true;
355 return false;
356}
357 /*}}}*/
358// DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides /*{{{*/
359// ---------------------------------------------------------------------
360/* This intellegently looks at dep target packages and tries to figure
361 out which package should be used. This is needed to nicely handle
362 provide mapping. If the target package has no other providing packages
363 then it returned. Otherwise the providing list is looked at to
364 see if there is one one unique providing package if so it is returned.
365 Otherwise true is returned and the target package is set. The return
b2e465d6
AL
366 result indicates whether the node should be expandable
367
368 In Conjunction with the DepCache the value of Result may not be
369 super-good since the policy may have made it uninstallable. Using
370 AllTargets is better in this case. */
578bfd0a
AL
371bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result)
372{
373 Result = TargetPkg();
374
375 // No provides at all
376 if (Result->ProvidesList == 0)
377 return false;
378
379 // There is the Base package and the providing ones which is at least 2
380 if (Result->VersionList != 0)
381 return true;
382
383 /* We have to skip over indirect provisions of the package that
384 owns the dependency. For instance, if libc5-dev depends on the
385 virtual package libc-dev which is provided by libc5-dev and libc6-dev
386 we must ignore libc5-dev when considering the provides list. */
387 PrvIterator PStart = Result.ProvidesList();
388 for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); PStart++);
389
390 // Nothing but indirect self provides
391 if (PStart.end() == true)
392 return false;
393
394 // Check for single packages in the provides list
395 PrvIterator P = PStart;
396 for (; P.end() != true; P++)
397 {
398 // Skip over self provides
399 if (P.OwnerPkg() == ParentPkg())
400 continue;
401 if (PStart.OwnerPkg() != P.OwnerPkg())
402 break;
403 }
b2e465d6
AL
404
405 Result = PStart.OwnerPkg();
578bfd0a
AL
406
407 // Check for non dups
408 if (P.end() != true)
409 return true;
b2e465d6 410
578bfd0a
AL
411 return false;
412}
413 /*}}}*/
414// DepIterator::AllTargets - Returns the set of all possible targets /*{{{*/
415// ---------------------------------------------------------------------
b2e465d6 416/* This is a more useful version of TargetPkg() that follows versioned
578bfd0a 417 provides. It includes every possible package-version that could satisfy
fbfb2a7c
AL
418 the dependency. The last item in the list has a 0. The resulting pointer
419 must be delete [] 'd */
578bfd0a
AL
420pkgCache::Version **pkgCache::DepIterator::AllTargets()
421{
422 Version **Res = 0;
423 unsigned long Size =0;
424 while (1)
425 {
426 Version **End = Res;
427 PkgIterator DPkg = TargetPkg();
428
429 // Walk along the actual package providing versions
430 for (VerIterator I = DPkg.VersionList(); I.end() == false; I++)
431 {
b2e465d6 432 if (Owner->VS->CheckDep(I.VerStr(),Dep->CompareOp,TargetVer()) == false)
578bfd0a
AL
433 continue;
434
b2e465d6 435 if ((Dep->Type == pkgCache::Dep::Conflicts ||
308c7d30 436 Dep->Type == pkgCache::Dep::DpkgBreaks ||
b2e465d6 437 Dep->Type == pkgCache::Dep::Obsoletes) &&
f07b5628 438 ParentPkg() == I.ParentPkg())
578bfd0a
AL
439 continue;
440
441 Size++;
442 if (Res != 0)
443 *End++ = I;
444 }
445
446 // Follow all provides
447 for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; I++)
448 {
b2e465d6 449 if (Owner->VS->CheckDep(I.ProvideVersion(),Dep->CompareOp,TargetVer()) == false)
578bfd0a
AL
450 continue;
451
b2e465d6 452 if ((Dep->Type == pkgCache::Dep::Conflicts ||
308c7d30 453 Dep->Type == pkgCache::Dep::DpkgBreaks ||
b2e465d6 454 Dep->Type == pkgCache::Dep::Obsoletes) &&
f07b5628 455 ParentPkg() == I.OwnerPkg())
578bfd0a
AL
456 continue;
457
458 Size++;
459 if (Res != 0)
460 *End++ = I.OwnerVer();
461 }
462
463 // Do it again and write it into the array
464 if (Res == 0)
465 {
466 Res = new Version *[Size+1];
467 Size = 0;
468 }
469 else
470 {
471 *End = 0;
472 break;
473 }
474 }
475
476 return Res;
477}
478 /*}}}*/
43d017d6
AL
479// DepIterator::GlobOr - Compute an OR group /*{{{*/
480// ---------------------------------------------------------------------
481/* This Takes an iterator, iterates past the current dependency grouping
482 and returns Start and End so that so End is the final element
483 in the group, if End == Start then D is End++ and End is the
484 dependency D was pointing to. Use in loops to iterate sensibly. */
485void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End)
486{
487 // Compute a single dependency element (glob or)
488 Start = *this;
489 End = *this;
018f1533 490 for (bool LastOR = true; end() == false && LastOR == true;)
43d017d6
AL
491 {
492 LastOR = (Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
018f1533 493 (*this)++;
43d017d6
AL
494 if (LastOR == true)
495 End = (*this);
496 }
497}
498 /*}}}*/
578bfd0a
AL
499// VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/
500// ---------------------------------------------------------------------
501/* This just looks over the version list to see if B is listed before A. In
502 most cases this will return in under 4 checks, ver lists are short. */
503int pkgCache::VerIterator::CompareVer(const VerIterator &B) const
504{
505 // Check if they are equal
506 if (*this == B)
507 return 0;
508 if (end() == true)
509 return -1;
510 if (B.end() == true)
511 return 1;
512
513 /* Start at A and look for B. If B is found then A > B otherwise
514 B was before A so A < B */
515 VerIterator I = *this;
516 for (;I.end() == false; I++)
517 if (I == B)
518 return 1;
519 return -1;
520}
521 /*}}}*/
b518cca6
AL
522// VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/
523// ---------------------------------------------------------------------
524/* */
525bool pkgCache::VerIterator::Downloadable() const
526{
527 VerFileIterator Files = FileList();
528 for (; Files.end() == false; Files++)
f07b5628 529 if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource)
b518cca6
AL
530 return true;
531 return false;
532}
533 /*}}}*/
3c124dde
AL
534// VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/
535// ---------------------------------------------------------------------
536/* This checks to see if any of the versions files are not NotAutomatic.
537 True if this version is selectable for automatic installation. */
538bool pkgCache::VerIterator::Automatic() const
539{
540 VerFileIterator Files = FileList();
541 for (; Files.end() == false; Files++)
542 if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic)
543 return true;
544 return false;
545}
546 /*}}}*/
547// VerIterator::NewestFile - Return the newest file version relation /*{{{*/
548// ---------------------------------------------------------------------
549/* This looks at the version numbers associated with all of the sources
550 this version is in and returns the highest.*/
551pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const
552{
553 VerFileIterator Files = FileList();
554 VerFileIterator Highest = Files;
555 for (; Files.end() == false; Files++)
556 {
b2e465d6 557 if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0)
3c124dde
AL
558 Highest = Files;
559 }
560
561 return Highest;
562}
563 /*}}}*/
b2e465d6
AL
564// VerIterator::RelStr - Release description string /*{{{*/
565// ---------------------------------------------------------------------
566/* This describes the version from a release-centric manner. The output is a
567 list of Label:Version/Archive */
568string pkgCache::VerIterator::RelStr()
569{
570 bool First = true;
571 string Res;
572 for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; I++)
573 {
574 // Do not print 'not source' entries'
575 pkgCache::PkgFileIterator File = I.File();
576 if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
577 continue;
578
579 // See if we have already printed this out..
580 bool Seen = false;
581 for (pkgCache::VerFileIterator J = this->FileList(); I != J; J++)
582 {
583 pkgCache::PkgFileIterator File2 = J.File();
584 if (File2->Label == 0 || File->Label == 0)
585 continue;
586
587 if (strcmp(File.Label(),File2.Label()) != 0)
588 continue;
589
590 if (File2->Version == File->Version)
591 {
592 Seen = true;
593 break;
594 }
10639577 595 if (File2->Version == 0 || File->Version == 0)
b2e465d6
AL
596 break;
597 if (strcmp(File.Version(),File2.Version()) == 0)
598 Seen = true;
599 }
600
601 if (Seen == true)
602 continue;
603
604 if (First == false)
605 Res += ", ";
606 else
607 First = false;
608
609 if (File->Label != 0)
610 Res = Res + File.Label() + ':';
611
612 if (File->Archive != 0)
613 {
614 if (File->Version == 0)
615 Res += File.Archive();
616 else
617 Res = Res + File.Version() + '/' + File.Archive();
618 }
619 else
620 {
621 // No release file, print the host name that this came from
622 if (File->Site == 0 || File.Site()[0] == 0)
623 Res += "localhost";
624 else
625 Res += File.Site();
626 }
627 }
628 return Res;
629}
630 /*}}}*/
578bfd0a
AL
631// PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/
632// ---------------------------------------------------------------------
633/* This stats the file and compares its stats with the ones that were
634 stored during generation. Date checks should probably also be
635 included here. */
636bool pkgCache::PkgFileIterator::IsOk()
637{
638 struct stat Buf;
639 if (stat(FileName(),&Buf) != 0)
640 return false;
641
642 if (Buf.st_size != (signed)File->Size || Buf.st_mtime != File->mtime)
643 return false;
644
645 return true;
646}
647 /*}}}*/
af87ab54
AL
648// PkgFileIterator::RelStr - Return the release string /*{{{*/
649// ---------------------------------------------------------------------
650/* */
651string pkgCache::PkgFileIterator::RelStr()
652{
653 string Res;
654 if (Version() != 0)
655 Res = Res + (Res.empty() == true?"v=":",v=") + Version();
656 if (Origin() != 0)
657 Res = Res + (Res.empty() == true?"o=":",o=") + Origin();
658 if (Archive() != 0)
659 Res = Res + (Res.empty() == true?"a=":",a=") + Archive();
efc487fb
DK
660 if (Codename() != 0)
661 Res = Res + (Res.empty() == true?"n=":",n=") + Codename();
af87ab54
AL
662 if (Label() != 0)
663 Res = Res + (Res.empty() == true?"l=":",l=") + Label();
664 if (Component() != 0)
665 Res = Res + (Res.empty() == true?"c=":",c=") + Component();
666 return Res;
667}
668 /*}}}*/
012b102a
MV
669// VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
670// ---------------------------------------------------------------------
671/* return a DescIter for the current locale or the default if none is
672 * found
673 */
674pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
675{
676 pkgCache::DescIterator DescDefault = DescriptionList();
677 pkgCache::DescIterator Desc = DescDefault;
678 for (; Desc.end() == false; Desc++)
679 if (pkgIndexFile::LanguageCode() == Desc.LanguageCode())
680 break;
c76c44b1 681 if (Desc.end() == true)
682 Desc = DescDefault;
012b102a
MV
683 return Desc;
684};
685
686 /*}}}*/