pkgcache.cc 21 KB

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