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