pkgcachegen.cc 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcachegen.cc,v 1.53.2.1 2003/12/24 23:09:17 mdz Exp $
  4. /* ######################################################################
  5. Package Cache Generator - Generator for the cache structure.
  6. This builds the cache structure from the abstract package list parser.
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <config.h>
  11. #include <apt-pkg/pkgcachegen.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/version.h>
  14. #include <apt-pkg/progress.h>
  15. #include <apt-pkg/sourcelist.h>
  16. #include <apt-pkg/configuration.h>
  17. #include <apt-pkg/strutl.h>
  18. #include <apt-pkg/sptr.h>
  19. #include <apt-pkg/pkgsystem.h>
  20. #include <apt-pkg/macros.h>
  21. #include <apt-pkg/metaindex.h>
  22. #include <apt-pkg/fileutl.h>
  23. #include <apt-pkg/hashsum_template.h>
  24. #include <apt-pkg/indexfile.h>
  25. #include <apt-pkg/md5.h>
  26. #include <apt-pkg/mmap.h>
  27. #include <apt-pkg/pkgcache.h>
  28. #include <apt-pkg/cacheiterators.h>
  29. #include <stddef.h>
  30. #include <string.h>
  31. #include <iostream>
  32. #include <string>
  33. #include <vector>
  34. #include <sys/stat.h>
  35. #include <unistd.h>
  36. #include <apti18n.h>
  37. /*}}}*/
  38. typedef std::vector<pkgIndexFile *>::iterator FileIterator;
  39. template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
  40. static bool IsDuplicateDescription(pkgCache::DescIterator Desc,
  41. MD5SumValue const &CurMd5, std::string const &CurLang);
  42. using std::string;
  43. // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
  44. // ---------------------------------------------------------------------
  45. /* We set the dirty flag and make sure that is written to the disk */
  46. pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
  47. Map(*pMap), Cache(pMap,false), Progress(Prog),
  48. FoundFileDeps(0)
  49. {
  50. CurrentFile = 0;
  51. memset(UniqHash,0,sizeof(UniqHash));
  52. if (_error->PendingError() == true)
  53. return;
  54. if (Map.Size() == 0)
  55. {
  56. // Setup the map interface..
  57. Cache.HeaderP = (pkgCache::Header *)Map.Data();
  58. if (Map.RawAllocate(sizeof(pkgCache::Header)) == 0 && _error->PendingError() == true)
  59. return;
  60. Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
  61. // Starting header
  62. *Cache.HeaderP = pkgCache::Header();
  63. map_ptrloc const idxVerSysName = WriteStringInMap(_system->VS->Label);
  64. if (unlikely(idxVerSysName == 0))
  65. return;
  66. Cache.HeaderP->VerSysName = idxVerSysName;
  67. // this pointer is set in ReMap, but we need it now for WriteUniqString
  68. Cache.StringItemP = (pkgCache::StringItem *)Map.Data();
  69. map_ptrloc const idxArchitecture = WriteUniqString(_config->Find("APT::Architecture"));
  70. if (unlikely(idxArchitecture == 0))
  71. return;
  72. Cache.HeaderP->Architecture = idxArchitecture;
  73. std::vector<std::string> archs = APT::Configuration::getArchitectures();
  74. if (archs.size() > 1)
  75. {
  76. std::vector<std::string>::const_iterator a = archs.begin();
  77. std::string list = *a;
  78. for (++a; a != archs.end(); ++a)
  79. list.append(",").append(*a);
  80. map_ptrloc const idxArchitectures = WriteStringInMap(list);
  81. if (unlikely(idxArchitectures == 0))
  82. return;
  83. Cache.HeaderP->Architectures = idxArchitectures;
  84. }
  85. else
  86. Cache.HeaderP->Architectures = idxArchitecture;
  87. Cache.ReMap();
  88. }
  89. else
  90. {
  91. // Map directly from the existing file
  92. Cache.ReMap();
  93. Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
  94. if (Cache.VS != _system->VS)
  95. {
  96. _error->Error(_("Cache has an incompatible versioning system"));
  97. return;
  98. }
  99. }
  100. Cache.HeaderP->Dirty = true;
  101. Map.Sync(0,sizeof(pkgCache::Header));
  102. }
  103. /*}}}*/
  104. // CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
  105. // ---------------------------------------------------------------------
  106. /* We sync the data then unset the dirty flag in two steps so as to
  107. advoid a problem during a crash */
  108. pkgCacheGenerator::~pkgCacheGenerator()
  109. {
  110. if (_error->PendingError() == true)
  111. return;
  112. if (Map.Sync() == false)
  113. return;
  114. Cache.HeaderP->Dirty = false;
  115. Cache.HeaderP->CacheFileSize = Map.Size();
  116. Map.Sync(0,sizeof(pkgCache::Header));
  117. }
  118. /*}}}*/
  119. void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap) {/*{{{*/
  120. if (oldMap == newMap)
  121. return;
  122. if (_config->FindB("Debug::pkgCacheGen", false))
  123. std::clog << "Remaping from " << oldMap << " to " << newMap << std::endl;
  124. Cache.ReMap(false);
  125. CurrentFile += (pkgCache::PackageFile const * const) newMap - (pkgCache::PackageFile const * const) oldMap;
  126. for (size_t i = 0; i < _count(UniqHash); ++i)
  127. if (UniqHash[i] != 0)
  128. UniqHash[i] += (pkgCache::StringItem const * const) newMap - (pkgCache::StringItem const * const) oldMap;
  129. for (std::vector<pkgCache::GrpIterator*>::const_iterator i = Dynamic<pkgCache::GrpIterator>::toReMap.begin();
  130. i != Dynamic<pkgCache::GrpIterator>::toReMap.end(); ++i)
  131. (*i)->ReMap(oldMap, newMap);
  132. for (std::vector<pkgCache::PkgIterator*>::const_iterator i = Dynamic<pkgCache::PkgIterator>::toReMap.begin();
  133. i != Dynamic<pkgCache::PkgIterator>::toReMap.end(); ++i)
  134. (*i)->ReMap(oldMap, newMap);
  135. for (std::vector<pkgCache::VerIterator*>::const_iterator i = Dynamic<pkgCache::VerIterator>::toReMap.begin();
  136. i != Dynamic<pkgCache::VerIterator>::toReMap.end(); ++i)
  137. (*i)->ReMap(oldMap, newMap);
  138. for (std::vector<pkgCache::DepIterator*>::const_iterator i = Dynamic<pkgCache::DepIterator>::toReMap.begin();
  139. i != Dynamic<pkgCache::DepIterator>::toReMap.end(); ++i)
  140. (*i)->ReMap(oldMap, newMap);
  141. for (std::vector<pkgCache::DescIterator*>::const_iterator i = Dynamic<pkgCache::DescIterator>::toReMap.begin();
  142. i != Dynamic<pkgCache::DescIterator>::toReMap.end(); ++i)
  143. (*i)->ReMap(oldMap, newMap);
  144. for (std::vector<pkgCache::PrvIterator*>::const_iterator i = Dynamic<pkgCache::PrvIterator>::toReMap.begin();
  145. i != Dynamic<pkgCache::PrvIterator>::toReMap.end(); ++i)
  146. (*i)->ReMap(oldMap, newMap);
  147. for (std::vector<pkgCache::PkgFileIterator*>::const_iterator i = Dynamic<pkgCache::PkgFileIterator>::toReMap.begin();
  148. i != Dynamic<pkgCache::PkgFileIterator>::toReMap.end(); ++i)
  149. (*i)->ReMap(oldMap, newMap);
  150. } /*}}}*/
  151. // CacheGenerator::WriteStringInMap /*{{{*/
  152. map_ptrloc pkgCacheGenerator::WriteStringInMap(const char *String,
  153. const unsigned long &Len) {
  154. void const * const oldMap = Map.Data();
  155. map_ptrloc const index = Map.WriteString(String, Len);
  156. if (index != 0)
  157. ReMap(oldMap, Map.Data());
  158. return index;
  159. }
  160. /*}}}*/
  161. // CacheGenerator::WriteStringInMap /*{{{*/
  162. map_ptrloc pkgCacheGenerator::WriteStringInMap(const char *String) {
  163. void const * const oldMap = Map.Data();
  164. map_ptrloc const index = Map.WriteString(String);
  165. if (index != 0)
  166. ReMap(oldMap, Map.Data());
  167. return index;
  168. }
  169. /*}}}*/
  170. map_ptrloc pkgCacheGenerator::AllocateInMap(const unsigned long &size) {/*{{{*/
  171. void const * const oldMap = Map.Data();
  172. map_ptrloc const index = Map.Allocate(size);
  173. if (index != 0)
  174. ReMap(oldMap, Map.Data());
  175. return index;
  176. }
  177. /*}}}*/
  178. // CacheGenerator::MergeList - Merge the package list /*{{{*/
  179. // ---------------------------------------------------------------------
  180. /* This provides the generation of the entries in the cache. Each loop
  181. goes through a single package record from the underlying parse engine. */
  182. bool pkgCacheGenerator::MergeList(ListParser &List,
  183. pkgCache::VerIterator *OutVer)
  184. {
  185. List.Owner = this;
  186. unsigned int Counter = 0;
  187. while (List.Step() == true)
  188. {
  189. string const PackageName = List.Package();
  190. if (PackageName.empty() == true)
  191. return false;
  192. Counter++;
  193. if (Counter % 100 == 0 && Progress != 0)
  194. Progress->Progress(List.Offset());
  195. string Arch = List.Architecture();
  196. string const Version = List.Version();
  197. if (Version.empty() == true && Arch.empty() == true)
  198. {
  199. // package descriptions
  200. if (MergeListGroup(List, PackageName) == false)
  201. return false;
  202. continue;
  203. }
  204. if (Arch.empty() == true)
  205. {
  206. // use the pseudo arch 'none' for arch-less packages
  207. Arch = "none";
  208. /* We might built a SingleArchCache here, which we don't want to blow up
  209. just for these :none packages to a proper MultiArchCache, so just ensure
  210. that we have always a native package structure first for SingleArch */
  211. pkgCache::PkgIterator NP;
  212. Dynamic<pkgCache::PkgIterator> DynPkg(NP);
  213. if (NewPackage(NP, PackageName, _config->Find("APT::Architecture")) == false)
  214. // TRANSLATOR: The first placeholder is a package name,
  215. // the other two should be copied verbatim as they include debug info
  216. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  217. PackageName.c_str(), "NewPackage", 0);
  218. }
  219. // Get a pointer to the package structure
  220. pkgCache::PkgIterator Pkg;
  221. Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
  222. if (NewPackage(Pkg, PackageName, Arch) == false)
  223. // TRANSLATOR: The first placeholder is a package name,
  224. // the other two should be copied verbatim as they include debug info
  225. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  226. PackageName.c_str(), "NewPackage", 1);
  227. if (Version.empty() == true)
  228. {
  229. if (MergeListPackage(List, Pkg) == false)
  230. return false;
  231. }
  232. else
  233. {
  234. if (MergeListVersion(List, Pkg, Version, OutVer) == false)
  235. return false;
  236. }
  237. if (OutVer != 0)
  238. {
  239. FoundFileDeps |= List.HasFileDeps();
  240. return true;
  241. }
  242. }
  243. if (Cache.HeaderP->PackageCount >= (1ULL<<sizeof(Cache.PkgP->ID)*8)-1)
  244. return _error->Error(_("Wow, you exceeded the number of package "
  245. "names this APT is capable of."));
  246. if (Cache.HeaderP->VersionCount >= (1ULL<<(sizeof(Cache.VerP->ID)*8))-1)
  247. return _error->Error(_("Wow, you exceeded the number of versions "
  248. "this APT is capable of."));
  249. if (Cache.HeaderP->DescriptionCount >= (1ULL<<(sizeof(Cache.DescP->ID)*8))-1)
  250. return _error->Error(_("Wow, you exceeded the number of descriptions "
  251. "this APT is capable of."));
  252. if (Cache.HeaderP->DependsCount >= (1ULL<<(sizeof(Cache.DepP->ID)*8))-1ULL)
  253. return _error->Error(_("Wow, you exceeded the number of dependencies "
  254. "this APT is capable of."));
  255. FoundFileDeps |= List.HasFileDeps();
  256. return true;
  257. }
  258. // CacheGenerator::MergeListGroup /*{{{*/
  259. bool pkgCacheGenerator::MergeListGroup(ListParser &List, std::string const &GrpName)
  260. {
  261. pkgCache::GrpIterator Grp = Cache.FindGrp(GrpName);
  262. // a group has no data on it's own, only packages have it but these
  263. // stanzas like this come from Translation- files to add descriptions,
  264. // but without a version we don't need a description for it…
  265. if (Grp.end() == true)
  266. return true;
  267. Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
  268. pkgCache::PkgIterator Pkg;
  269. Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
  270. for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  271. if (MergeListPackage(List, Pkg) == false)
  272. return false;
  273. return true;
  274. }
  275. /*}}}*/
  276. // CacheGenerator::MergeListPackage /*{{{*/
  277. bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg)
  278. {
  279. // we first process the package, then the descriptions
  280. // (for deb this package processing is in fact a no-op)
  281. pkgCache::VerIterator Ver(Cache);
  282. Dynamic<pkgCache::VerIterator> DynVer(Ver);
  283. if (List.UsePackage(Pkg, Ver) == false)
  284. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  285. Pkg.Name(), "UsePackage", 1);
  286. // Find the right version to write the description
  287. MD5SumValue CurMd5 = List.Description_md5();
  288. if (CurMd5.Value().empty() == true && List.Description("").empty() == true)
  289. return true;
  290. std::vector<std::string> availDesc = List.AvailableDescriptionLanguages();
  291. for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
  292. {
  293. pkgCache::DescIterator VerDesc = Ver.DescriptionList();
  294. // a version can only have one md5 describing it
  295. if (VerDesc.end() == true || MD5SumValue(VerDesc.md5()) != CurMd5)
  296. continue;
  297. map_ptrloc md5idx = VerDesc->md5sum;
  298. for (std::vector<std::string>::const_iterator CurLang = availDesc.begin(); CurLang != availDesc.end(); ++CurLang)
  299. {
  300. // don't add a new description if we have one for the given
  301. // md5 && language
  302. if (IsDuplicateDescription(VerDesc, CurMd5, *CurLang) == true)
  303. continue;
  304. AddNewDescription(List, Ver, *CurLang, CurMd5, md5idx);
  305. }
  306. // we can stop here as all "same" versions will share the description
  307. break;
  308. }
  309. return true;
  310. }
  311. /*}}}*/
  312. // CacheGenerator::MergeListVersion /*{{{*/
  313. bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
  314. std::string const &Version, pkgCache::VerIterator* &OutVer)
  315. {
  316. pkgCache::VerIterator Ver = Pkg.VersionList();
  317. Dynamic<pkgCache::VerIterator> DynVer(Ver);
  318. map_ptrloc *LastVer = &Pkg->VersionList;
  319. void const * oldMap = Map.Data();
  320. unsigned short const Hash = List.VersionHash();
  321. if (Ver.end() == false)
  322. {
  323. /* We know the list is sorted so we use that fact in the search.
  324. Insertion of new versions is done with correct sorting */
  325. int Res = 1;
  326. for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++)
  327. {
  328. Res = Cache.VS->CmpVersion(Version,Ver.VerStr());
  329. // Version is higher as current version - insert here
  330. if (Res > 0)
  331. break;
  332. // Versionstrings are equal - is hash also equal?
  333. if (Res == 0 && List.SameVersion(Hash, Ver) == true)
  334. break;
  335. // proceed with the next till we have either the right
  336. // or we found another version (which will be lower)
  337. }
  338. /* We already have a version for this item, record that we saw it */
  339. if (Res == 0 && Ver.end() == false && Ver->Hash == Hash)
  340. {
  341. if (List.UsePackage(Pkg,Ver) == false)
  342. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  343. Pkg.Name(), "UsePackage", 2);
  344. if (NewFileVer(Ver,List) == false)
  345. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  346. Pkg.Name(), "NewFileVer", 1);
  347. // Read only a single record and return
  348. if (OutVer != 0)
  349. {
  350. *OutVer = Ver;
  351. return true;
  352. }
  353. return true;
  354. }
  355. }
  356. // Add a new version
  357. map_ptrloc const verindex = NewVersion(Ver, Version, Pkg.Index(), Hash, *LastVer);
  358. if (verindex == 0 && _error->PendingError())
  359. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  360. Pkg.Name(), "NewVersion", 1);
  361. if (oldMap != Map.Data())
  362. LastVer += (map_ptrloc const * const) Map.Data() - (map_ptrloc const * const) oldMap;
  363. *LastVer = verindex;
  364. if (unlikely(List.NewVersion(Ver) == false))
  365. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  366. Pkg.Name(), "NewVersion", 2);
  367. if (unlikely(List.UsePackage(Pkg,Ver) == false))
  368. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  369. Pkg.Name(), "UsePackage", 3);
  370. if (unlikely(NewFileVer(Ver,List) == false))
  371. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  372. Pkg.Name(), "NewFileVer", 2);
  373. pkgCache::GrpIterator Grp = Pkg.Group();
  374. Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
  375. /* If it is the first version of this package we need to add implicit
  376. Multi-Arch dependencies to all other package versions in the group now -
  377. otherwise we just add them for this new version */
  378. if (Pkg.VersionList()->NextVer == 0)
  379. {
  380. pkgCache::PkgIterator P = Grp.PackageList();
  381. Dynamic<pkgCache::PkgIterator> DynP(P);
  382. for (; P.end() != true; P = Grp.NextPkg(P))
  383. {
  384. if (P->ID == Pkg->ID)
  385. continue;
  386. pkgCache::VerIterator V = P.VersionList();
  387. Dynamic<pkgCache::VerIterator> DynV(V);
  388. for (; V.end() != true; ++V)
  389. if (unlikely(AddImplicitDepends(V, Pkg) == false))
  390. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  391. Pkg.Name(), "AddImplicitDepends", 1);
  392. }
  393. /* :none packages are packages without an architecture. They are forbidden by
  394. debian-policy, so usually they will only be in (old) dpkg status files -
  395. and dpkg will complain about them - and are pretty rare. We therefore do
  396. usually not create conflicts while the parent is created, but only if a :none
  397. package (= the target) appears. This creates incorrect dependencies on :none
  398. for architecture-specific dependencies on the package we copy from, but we
  399. will ignore this bug as architecture-specific dependencies are only allowed
  400. in jessie and until then the :none packages should be extinct (hopefully).
  401. In other words: This should work long enough to allow graceful removal of
  402. these packages, it is not supposed to allow users to keep using them … */
  403. if (strcmp(Pkg.Arch(), "none") == 0)
  404. {
  405. pkgCache::PkgIterator M = Grp.FindPreferredPkg();
  406. if (M.end() == false && Pkg != M)
  407. {
  408. pkgCache::DepIterator D = M.RevDependsList();
  409. Dynamic<pkgCache::DepIterator> DynD(D);
  410. for (; D.end() == false; ++D)
  411. {
  412. if ((D->Type != pkgCache::Dep::Conflicts &&
  413. D->Type != pkgCache::Dep::DpkgBreaks &&
  414. D->Type != pkgCache::Dep::Replaces) ||
  415. D.ParentPkg().Group() == Grp)
  416. continue;
  417. map_ptrloc *OldDepLast = NULL;
  418. pkgCache::VerIterator ConVersion = D.ParentVer();
  419. Dynamic<pkgCache::VerIterator> DynV(ConVersion);
  420. // duplicate the Conflicts/Breaks/Replaces for :none arch
  421. NewDepends(Pkg, ConVersion, D->Version,
  422. D->CompareOp, D->Type, OldDepLast);
  423. }
  424. }
  425. }
  426. }
  427. if (unlikely(AddImplicitDepends(Grp, Pkg, Ver) == false))
  428. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  429. Pkg.Name(), "AddImplicitDepends", 2);
  430. // Read only a single record and return
  431. if (OutVer != 0)
  432. {
  433. *OutVer = Ver;
  434. return true;
  435. }
  436. /* Record the Description(s) based on their master md5sum */
  437. MD5SumValue CurMd5 = List.Description_md5();
  438. if (CurMd5.Value().empty() == true && List.Description("").empty() == true)
  439. return true;
  440. /* Before we add a new description we first search in the group for
  441. a version with a description of the same MD5 - if so we reuse this
  442. description group instead of creating our own for this version */
  443. for (pkgCache::PkgIterator P = Grp.PackageList();
  444. P.end() == false; P = Grp.NextPkg(P))
  445. {
  446. for (pkgCache::VerIterator V = P.VersionList();
  447. V.end() == false; ++V)
  448. {
  449. if (V->DescriptionList == 0 || MD5SumValue(V.DescriptionList().md5()) != CurMd5)
  450. continue;
  451. Ver->DescriptionList = V->DescriptionList;
  452. }
  453. }
  454. // We haven't found reusable descriptions, so add the first description(s)
  455. map_ptrloc md5idx = Ver->DescriptionList == 0 ? 0 : Ver.DescriptionList()->md5sum;
  456. std::vector<std::string> availDesc = List.AvailableDescriptionLanguages();
  457. for (std::vector<std::string>::const_iterator CurLang = availDesc.begin(); CurLang != availDesc.end(); ++CurLang)
  458. if (AddNewDescription(List, Ver, *CurLang, CurMd5, md5idx) == false)
  459. return false;
  460. return true;
  461. }
  462. /*}}}*/
  463. bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, std::string const &lang, MD5SumValue const &CurMd5, map_ptrloc &md5idx) /*{{{*/
  464. {
  465. pkgCache::DescIterator Desc;
  466. Dynamic<pkgCache::DescIterator> DynDesc(Desc);
  467. map_ptrloc const descindex = NewDescription(Desc, lang, CurMd5, md5idx);
  468. if (unlikely(descindex == 0 && _error->PendingError()))
  469. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  470. Ver.ParentPkg().Name(), "NewDescription", 1);
  471. md5idx = Desc->md5sum;
  472. Desc->ParentPkg = Ver.ParentPkg().Index();
  473. // we add at the end, so that the start is constant as we need
  474. // that to be able to efficiently share these lists
  475. pkgCache::DescIterator VerDesc = Ver.DescriptionList(); // old value might be invalid after ReMap
  476. for (;VerDesc.end() == false && VerDesc->NextDesc != 0; ++VerDesc);
  477. map_ptrloc * const LastNextDesc = (VerDesc.end() == true) ? &Ver->DescriptionList : &VerDesc->NextDesc;
  478. *LastNextDesc = descindex;
  479. if (NewFileDesc(Desc,List) == false)
  480. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  481. Ver.ParentPkg().Name(), "NewFileDesc", 1);
  482. return true;
  483. }
  484. /*}}}*/
  485. /*}}}*/
  486. // CacheGenerator::MergeFileProvides - Merge file provides /*{{{*/
  487. // ---------------------------------------------------------------------
  488. /* If we found any file depends while parsing the main list we need to
  489. resolve them. Since it is undesired to load the entire list of files
  490. into the cache as virtual packages we do a two stage effort. MergeList
  491. identifies the file depends and this creates Provdies for them by
  492. re-parsing all the indexs. */
  493. bool pkgCacheGenerator::MergeFileProvides(ListParser &List)
  494. {
  495. List.Owner = this;
  496. unsigned int Counter = 0;
  497. while (List.Step() == true)
  498. {
  499. string PackageName = List.Package();
  500. if (PackageName.empty() == true)
  501. return false;
  502. string Version = List.Version();
  503. if (Version.empty() == true)
  504. continue;
  505. pkgCache::PkgIterator Pkg = Cache.FindPkg(PackageName);
  506. Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
  507. if (Pkg.end() == true)
  508. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  509. PackageName.c_str(), "FindPkg", 1);
  510. Counter++;
  511. if (Counter % 100 == 0 && Progress != 0)
  512. Progress->Progress(List.Offset());
  513. unsigned short Hash = List.VersionHash();
  514. pkgCache::VerIterator Ver = Pkg.VersionList();
  515. Dynamic<pkgCache::VerIterator> DynVer(Ver);
  516. for (; Ver.end() == false; ++Ver)
  517. {
  518. if (List.SameVersion(Hash, Ver) == true && Version == Ver.VerStr())
  519. {
  520. if (List.CollectFileProvides(Cache,Ver) == false)
  521. return _error->Error(_("Error occurred while processing %s (%s%d)"),
  522. PackageName.c_str(), "CollectFileProvides", 1);
  523. break;
  524. }
  525. }
  526. if (Ver.end() == true)
  527. _error->Warning(_("Package %s %s was not found while processing file dependencies"),PackageName.c_str(),Version.c_str());
  528. }
  529. return true;
  530. }
  531. /*}}}*/
  532. // CacheGenerator::NewGroup - Add a new group /*{{{*/
  533. // ---------------------------------------------------------------------
  534. /* This creates a new group structure and adds it to the hash table */
  535. bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
  536. {
  537. Grp = Cache.FindGrp(Name);
  538. if (Grp.end() == false)
  539. return true;
  540. // Get a structure
  541. map_ptrloc const Group = AllocateInMap(sizeof(pkgCache::Group));
  542. if (unlikely(Group == 0))
  543. return false;
  544. Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group);
  545. map_ptrloc const idxName = WriteStringInMap(Name);
  546. if (unlikely(idxName == 0))
  547. return false;
  548. Grp->Name = idxName;
  549. // Insert it into the hash table
  550. unsigned long const Hash = Cache.Hash(Name);
  551. map_ptrloc *insertAt = &Cache.HeaderP->GrpHashTable[Hash];
  552. while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + *insertAt)->Name) > 0)
  553. insertAt = &(Cache.GrpP + *insertAt)->Next;
  554. Grp->Next = *insertAt;
  555. *insertAt = Group;
  556. Grp->ID = Cache.HeaderP->GroupCount++;
  557. return true;
  558. }
  559. /*}}}*/
  560. // CacheGenerator::NewPackage - Add a new package /*{{{*/
  561. // ---------------------------------------------------------------------
  562. /* This creates a new package structure and adds it to the hash table */
  563. bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name,
  564. const string &Arch) {
  565. pkgCache::GrpIterator Grp;
  566. Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
  567. if (unlikely(NewGroup(Grp, Name) == false))
  568. return false;
  569. Pkg = Grp.FindPkg(Arch);
  570. if (Pkg.end() == false)
  571. return true;
  572. // Get a structure
  573. map_ptrloc const Package = AllocateInMap(sizeof(pkgCache::Package));
  574. if (unlikely(Package == 0))
  575. return false;
  576. Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package);
  577. // Insert the package into our package list
  578. if (Grp->FirstPackage == 0) // the group is new
  579. {
  580. Grp->FirstPackage = Package;
  581. // Insert it into the hash table
  582. unsigned long const Hash = Cache.Hash(Name);
  583. map_ptrloc *insertAt = &Cache.HeaderP->PkgHashTable[Hash];
  584. while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.PkgP + *insertAt)->Name) > 0)
  585. insertAt = &(Cache.PkgP + *insertAt)->NextPackage;
  586. Pkg->NextPackage = *insertAt;
  587. *insertAt = Package;
  588. }
  589. else // Group the Packages together
  590. {
  591. // this package is the new last package
  592. pkgCache::PkgIterator LastPkg(Cache, Cache.PkgP + Grp->LastPackage);
  593. Pkg->NextPackage = LastPkg->NextPackage;
  594. LastPkg->NextPackage = Package;
  595. }
  596. Grp->LastPackage = Package;
  597. // Set the name, arch and the ID
  598. Pkg->Name = Grp->Name;
  599. Pkg->Group = Grp.Index();
  600. // all is mapped to the native architecture
  601. map_ptrloc const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str());
  602. if (unlikely(idxArch == 0))
  603. return false;
  604. Pkg->Arch = idxArch;
  605. Pkg->ID = Cache.HeaderP->PackageCount++;
  606. return true;
  607. }
  608. /*}}}*/
  609. // CacheGenerator::AddImplicitDepends /*{{{*/
  610. bool pkgCacheGenerator::AddImplicitDepends(pkgCache::GrpIterator &G,
  611. pkgCache::PkgIterator &P,
  612. pkgCache::VerIterator &V)
  613. {
  614. // copy P.Arch() into a string here as a cache remap
  615. // in NewDepends() later may alter the pointer location
  616. string Arch = P.Arch() == NULL ? "" : P.Arch();
  617. map_ptrloc *OldDepLast = NULL;
  618. /* MultiArch handling introduces a lot of implicit Dependencies:
  619. - MultiArch: same → Co-Installable if they have the same version
  620. - All others conflict with all other group members */
  621. bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same);
  622. pkgCache::PkgIterator D = G.PackageList();
  623. Dynamic<pkgCache::PkgIterator> DynD(D);
  624. map_ptrloc const VerStrIdx = V->VerStr;
  625. for (; D.end() != true; D = G.NextPkg(D))
  626. {
  627. if (Arch == D.Arch() || D->VersionList == 0)
  628. continue;
  629. /* We allow only one installed arch at the time
  630. per group, therefore each group member conflicts
  631. with all other group members */
  632. if (coInstall == true)
  633. {
  634. // Replaces: ${self}:other ( << ${binary:Version})
  635. NewDepends(D, V, VerStrIdx,
  636. pkgCache::Dep::Less, pkgCache::Dep::Replaces,
  637. OldDepLast);
  638. // Breaks: ${self}:other (!= ${binary:Version})
  639. NewDepends(D, V, VerStrIdx,
  640. pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks,
  641. OldDepLast);
  642. } else {
  643. // Conflicts: ${self}:other
  644. NewDepends(D, V, 0,
  645. pkgCache::Dep::NoOp, pkgCache::Dep::Conflicts,
  646. OldDepLast);
  647. }
  648. }
  649. return true;
  650. }
  651. bool pkgCacheGenerator::AddImplicitDepends(pkgCache::VerIterator &V,
  652. pkgCache::PkgIterator &D)
  653. {
  654. /* MultiArch handling introduces a lot of implicit Dependencies:
  655. - MultiArch: same → Co-Installable if they have the same version
  656. - All others conflict with all other group members */
  657. map_ptrloc *OldDepLast = NULL;
  658. bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same);
  659. if (coInstall == true)
  660. {
  661. map_ptrloc const VerStrIdx = V->VerStr;
  662. // Replaces: ${self}:other ( << ${binary:Version})
  663. NewDepends(D, V, VerStrIdx,
  664. pkgCache::Dep::Less, pkgCache::Dep::Replaces,
  665. OldDepLast);
  666. // Breaks: ${self}:other (!= ${binary:Version})
  667. NewDepends(D, V, VerStrIdx,
  668. pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks,
  669. OldDepLast);
  670. } else {
  671. // Conflicts: ${self}:other
  672. NewDepends(D, V, 0,
  673. pkgCache::Dep::NoOp, pkgCache::Dep::Conflicts,
  674. OldDepLast);
  675. }
  676. return true;
  677. }
  678. /*}}}*/
  679. // CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
  680. // ---------------------------------------------------------------------
  681. /* */
  682. bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
  683. ListParser &List)
  684. {
  685. if (CurrentFile == 0)
  686. return true;
  687. // Get a structure
  688. map_ptrloc const VerFile = AllocateInMap(sizeof(pkgCache::VerFile));
  689. if (VerFile == 0)
  690. return 0;
  691. pkgCache::VerFileIterator VF(Cache,Cache.VerFileP + VerFile);
  692. VF->File = CurrentFile - Cache.PkgFileP;
  693. // Link it to the end of the list
  694. map_ptrloc *Last = &Ver->FileList;
  695. for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; ++V)
  696. Last = &V->NextFile;
  697. VF->NextFile = *Last;
  698. *Last = VF.Index();
  699. VF->Offset = List.Offset();
  700. VF->Size = List.Size();
  701. if (Cache.HeaderP->MaxVerFileSize < VF->Size)
  702. Cache.HeaderP->MaxVerFileSize = VF->Size;
  703. Cache.HeaderP->VerFileCount++;
  704. return true;
  705. }
  706. /*}}}*/
  707. // CacheGenerator::NewVersion - Create a new Version /*{{{*/
  708. // ---------------------------------------------------------------------
  709. /* This puts a version structure in the linked list */
  710. unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
  711. const string &VerStr,
  712. map_ptrloc const ParentPkg,
  713. unsigned long const Hash,
  714. unsigned long Next)
  715. {
  716. // Get a structure
  717. map_ptrloc const Version = AllocateInMap(sizeof(pkgCache::Version));
  718. if (Version == 0)
  719. return 0;
  720. // Fill it in
  721. Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
  722. //Dynamic<pkgCache::VerIterator> DynV(Ver); // caller MergeListVersion already takes care of it
  723. Ver->NextVer = Next;
  724. Ver->ParentPkg = ParentPkg;
  725. Ver->Hash = Hash;
  726. Ver->ID = Cache.HeaderP->VersionCount++;
  727. // try to find the version string in the group for reuse
  728. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  729. pkgCache::GrpIterator Grp = Pkg.Group();
  730. if (Pkg.end() == false && Grp.end() == false)
  731. {
  732. for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P))
  733. {
  734. if (Pkg == P)
  735. continue;
  736. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
  737. {
  738. int const cmp = strcmp(V.VerStr(), VerStr.c_str());
  739. if (cmp == 0)
  740. {
  741. Ver->VerStr = V->VerStr;
  742. return Version;
  743. }
  744. else if (cmp < 0)
  745. break;
  746. }
  747. }
  748. }
  749. // haven't found the version string, so create
  750. map_ptrloc const idxVerStr = WriteStringInMap(VerStr);
  751. if (unlikely(idxVerStr == 0))
  752. return 0;
  753. Ver->VerStr = idxVerStr;
  754. return Version;
  755. }
  756. /*}}}*/
  757. // CacheGenerator::NewFileDesc - Create a new File<->Desc association /*{{{*/
  758. // ---------------------------------------------------------------------
  759. /* */
  760. bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc,
  761. ListParser &List)
  762. {
  763. if (CurrentFile == 0)
  764. return true;
  765. // Get a structure
  766. map_ptrloc const DescFile = AllocateInMap(sizeof(pkgCache::DescFile));
  767. if (DescFile == 0)
  768. return false;
  769. pkgCache::DescFileIterator DF(Cache,Cache.DescFileP + DescFile);
  770. DF->File = CurrentFile - Cache.PkgFileP;
  771. // Link it to the end of the list
  772. map_ptrloc *Last = &Desc->FileList;
  773. for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; ++D)
  774. Last = &D->NextFile;
  775. DF->NextFile = *Last;
  776. *Last = DF.Index();
  777. DF->Offset = List.Offset();
  778. DF->Size = List.Size();
  779. if (Cache.HeaderP->MaxDescFileSize < DF->Size)
  780. Cache.HeaderP->MaxDescFileSize = DF->Size;
  781. Cache.HeaderP->DescFileCount++;
  782. return true;
  783. }
  784. /*}}}*/
  785. // CacheGenerator::NewDescription - Create a new Description /*{{{*/
  786. // ---------------------------------------------------------------------
  787. /* This puts a description structure in the linked list */
  788. map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc,
  789. const string &Lang,
  790. const MD5SumValue &md5sum,
  791. map_ptrloc idxmd5str)
  792. {
  793. // Get a structure
  794. map_ptrloc const Description = AllocateInMap(sizeof(pkgCache::Description));
  795. if (Description == 0)
  796. return 0;
  797. // Fill it in
  798. Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description);
  799. Desc->ID = Cache.HeaderP->DescriptionCount++;
  800. map_ptrloc const idxlanguage_code = WriteUniqString(Lang);
  801. if (unlikely(idxlanguage_code == 0))
  802. return 0;
  803. Desc->language_code = idxlanguage_code;
  804. if (idxmd5str != 0)
  805. Desc->md5sum = idxmd5str;
  806. else
  807. {
  808. map_ptrloc const idxmd5sum = WriteStringInMap(md5sum.Value());
  809. if (unlikely(idxmd5sum == 0))
  810. return 0;
  811. Desc->md5sum = idxmd5sum;
  812. }
  813. return Description;
  814. }
  815. /*}}}*/
  816. // CacheGenerator::NewDepends - Create a dependency element /*{{{*/
  817. // ---------------------------------------------------------------------
  818. /* This creates a dependency element in the tree. It is linked to the
  819. version and to the package that it is pointing to. */
  820. bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
  821. pkgCache::VerIterator &Ver,
  822. string const &Version,
  823. unsigned int const &Op,
  824. unsigned int const &Type,
  825. map_ptrloc* &OldDepLast)
  826. {
  827. map_ptrloc index = 0;
  828. if (Version.empty() == false)
  829. {
  830. int const CmpOp = Op & 0x0F;
  831. // =-deps are used (79:1) for lockstep on same-source packages (e.g. data-packages)
  832. if (CmpOp == pkgCache::Dep::Equals && strcmp(Version.c_str(), Ver.VerStr()) == 0)
  833. index = Ver->VerStr;
  834. if (index == 0)
  835. {
  836. void const * const oldMap = Map.Data();
  837. index = WriteStringInMap(Version);
  838. if (unlikely(index == 0))
  839. return false;
  840. if (OldDepLast != 0 && oldMap != Map.Data())
  841. OldDepLast += (map_ptrloc const * const) Map.Data() - (map_ptrloc const * const) oldMap;
  842. }
  843. }
  844. return NewDepends(Pkg, Ver, index, Op, Type, OldDepLast);
  845. }
  846. bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
  847. pkgCache::VerIterator &Ver,
  848. map_ptrloc const Version,
  849. unsigned int const &Op,
  850. unsigned int const &Type,
  851. map_ptrloc* &OldDepLast)
  852. {
  853. void const * const oldMap = Map.Data();
  854. // Get a structure
  855. map_ptrloc const Dependency = AllocateInMap(sizeof(pkgCache::Dependency));
  856. if (unlikely(Dependency == 0))
  857. return false;
  858. // Fill it in
  859. pkgCache::DepIterator Dep(Cache,Cache.DepP + Dependency);
  860. Dynamic<pkgCache::DepIterator> DynDep(Dep);
  861. Dep->ParentVer = Ver.Index();
  862. Dep->Type = Type;
  863. Dep->CompareOp = Op;
  864. Dep->Version = Version;
  865. Dep->ID = Cache.HeaderP->DependsCount++;
  866. // Link it to the package
  867. Dep->Package = Pkg.Index();
  868. Dep->NextRevDepends = Pkg->RevDepends;
  869. Pkg->RevDepends = Dep.Index();
  870. // Do we know where to link the Dependency to?
  871. if (OldDepLast == NULL)
  872. {
  873. OldDepLast = &Ver->DependsList;
  874. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D)
  875. OldDepLast = &D->NextDepends;
  876. } else if (oldMap != Map.Data())
  877. OldDepLast += (map_ptrloc const * const) Map.Data() - (map_ptrloc const * const) oldMap;
  878. Dep->NextDepends = *OldDepLast;
  879. *OldDepLast = Dep.Index();
  880. OldDepLast = &Dep->NextDepends;
  881. return true;
  882. }
  883. /*}}}*/
  884. // ListParser::NewDepends - Create the environment for a new dependency /*{{{*/
  885. // ---------------------------------------------------------------------
  886. /* This creates a Group and the Package to link this dependency to if
  887. needed and handles also the caching of the old endpoint */
  888. bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator &Ver,
  889. const string &PackageName,
  890. const string &Arch,
  891. const string &Version,
  892. unsigned int Op,
  893. unsigned int Type)
  894. {
  895. pkgCache::GrpIterator Grp;
  896. Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
  897. if (unlikely(Owner->NewGroup(Grp, PackageName) == false))
  898. return false;
  899. // Locate the target package
  900. pkgCache::PkgIterator Pkg = Grp.FindPkg(Arch);
  901. // we don't create 'none' packages and their dependencies if we can avoid it …
  902. if (Pkg.end() == true && Arch == "none" && strcmp(Ver.ParentPkg().Arch(), "none") != 0)
  903. return true;
  904. Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
  905. if (Pkg.end() == true) {
  906. if (unlikely(Owner->NewPackage(Pkg, PackageName, Arch) == false))
  907. return false;
  908. }
  909. // Is it a file dependency?
  910. if (unlikely(PackageName[0] == '/'))
  911. FoundFileDeps = true;
  912. /* Caching the old end point speeds up generation substantially */
  913. if (OldDepVer != Ver) {
  914. OldDepLast = NULL;
  915. OldDepVer = Ver;
  916. }
  917. return Owner->NewDepends(Pkg, Ver, Version, Op, Type, OldDepLast);
  918. }
  919. /*}}}*/
  920. // ListParser::NewProvides - Create a Provides element /*{{{*/
  921. // ---------------------------------------------------------------------
  922. /* */
  923. bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator &Ver,
  924. const string &PkgName,
  925. const string &PkgArch,
  926. const string &Version)
  927. {
  928. pkgCache &Cache = Owner->Cache;
  929. // We do not add self referencing provides
  930. if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
  931. (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0)))
  932. return true;
  933. // Get a structure
  934. map_ptrloc const Provides = Owner->AllocateInMap(sizeof(pkgCache::Provides));
  935. if (unlikely(Provides == 0))
  936. return false;
  937. Cache.HeaderP->ProvidesCount++;
  938. // Fill it in
  939. pkgCache::PrvIterator Prv(Cache,Cache.ProvideP + Provides,Cache.PkgP);
  940. Dynamic<pkgCache::PrvIterator> DynPrv(Prv);
  941. Prv->Version = Ver.Index();
  942. Prv->NextPkgProv = Ver->ProvidesList;
  943. Ver->ProvidesList = Prv.Index();
  944. if (Version.empty() == false) {
  945. map_ptrloc const idxProvideVersion = WriteString(Version);
  946. Prv->ProvideVersion = idxProvideVersion;
  947. if (unlikely(idxProvideVersion == 0))
  948. return false;
  949. }
  950. // Locate the target package
  951. pkgCache::PkgIterator Pkg;
  952. Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
  953. if (unlikely(Owner->NewPackage(Pkg,PkgName, PkgArch) == false))
  954. return false;
  955. // Link it to the package
  956. Prv->ParentPkg = Pkg.Index();
  957. Prv->NextProvides = Pkg->ProvidesList;
  958. Pkg->ProvidesList = Prv.Index();
  959. return true;
  960. }
  961. /*}}}*/
  962. bool pkgCacheGenerator::ListParser::SameVersion(unsigned short const Hash,/*{{{*/
  963. pkgCache::VerIterator const &Ver)
  964. {
  965. return Hash == Ver->Hash;
  966. }
  967. /*}}}*/
  968. // CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
  969. // ---------------------------------------------------------------------
  970. /* This is used to select which file is to be associated with all newly
  971. added versions. The caller is responsible for setting the IMS fields. */
  972. bool pkgCacheGenerator::SelectFile(const string &File,const string &Site,
  973. const pkgIndexFile &Index,
  974. unsigned long Flags)
  975. {
  976. // Get some space for the structure
  977. map_ptrloc const idxFile = AllocateInMap(sizeof(*CurrentFile));
  978. if (unlikely(idxFile == 0))
  979. return false;
  980. CurrentFile = Cache.PkgFileP + idxFile;
  981. // Fill it in
  982. map_ptrloc const idxFileName = WriteStringInMap(File);
  983. map_ptrloc const idxSite = WriteUniqString(Site);
  984. if (unlikely(idxFileName == 0 || idxSite == 0))
  985. return false;
  986. CurrentFile->FileName = idxFileName;
  987. CurrentFile->Site = idxSite;
  988. CurrentFile->NextFile = Cache.HeaderP->FileList;
  989. CurrentFile->Flags = Flags;
  990. CurrentFile->ID = Cache.HeaderP->PackageFileCount;
  991. map_ptrloc const idxIndexType = WriteUniqString(Index.GetType()->Label);
  992. if (unlikely(idxIndexType == 0))
  993. return false;
  994. CurrentFile->IndexType = idxIndexType;
  995. PkgFileName = File;
  996. Cache.HeaderP->FileList = CurrentFile - Cache.PkgFileP;
  997. Cache.HeaderP->PackageFileCount++;
  998. if (Progress != 0)
  999. Progress->SubProgress(Index.Size());
  1000. return true;
  1001. }
  1002. /*}}}*/
  1003. // CacheGenerator::WriteUniqueString - Insert a unique string /*{{{*/
  1004. // ---------------------------------------------------------------------
  1005. /* This is used to create handles to strings. Given the same text it
  1006. always returns the same number */
  1007. unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
  1008. unsigned int Size)
  1009. {
  1010. /* We use a very small transient hash table here, this speeds up generation
  1011. by a fair amount on slower machines */
  1012. pkgCache::StringItem *&Bucket = UniqHash[(S[0]*5 + S[1]) % _count(UniqHash)];
  1013. if (Bucket != 0 &&
  1014. stringcmp(S,S+Size,Cache.StrP + Bucket->String) == 0)
  1015. return Bucket->String;
  1016. // Search for an insertion point
  1017. pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList;
  1018. int Res = 1;
  1019. map_ptrloc *Last = &Cache.HeaderP->StringList;
  1020. for (; I != Cache.StringItemP; Last = &I->NextItem,
  1021. I = Cache.StringItemP + I->NextItem)
  1022. {
  1023. Res = stringcmp(S,S+Size,Cache.StrP + I->String);
  1024. if (Res >= 0)
  1025. break;
  1026. }
  1027. // Match
  1028. if (Res == 0)
  1029. {
  1030. Bucket = I;
  1031. return I->String;
  1032. }
  1033. // Get a structure
  1034. void const * const oldMap = Map.Data();
  1035. map_ptrloc const Item = AllocateInMap(sizeof(pkgCache::StringItem));
  1036. if (Item == 0)
  1037. return 0;
  1038. map_ptrloc const idxString = WriteStringInMap(S,Size);
  1039. if (unlikely(idxString == 0))
  1040. return 0;
  1041. if (oldMap != Map.Data()) {
  1042. Last += (map_ptrloc const * const) Map.Data() - (map_ptrloc const * const) oldMap;
  1043. I += (pkgCache::StringItem const * const) Map.Data() - (pkgCache::StringItem const * const) oldMap;
  1044. }
  1045. *Last = Item;
  1046. // Fill in the structure
  1047. pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
  1048. ItemP->NextItem = I - Cache.StringItemP;
  1049. ItemP->String = idxString;
  1050. Bucket = ItemP;
  1051. return ItemP->String;
  1052. }
  1053. /*}}}*/
  1054. // CheckValidity - Check that a cache is up-to-date /*{{{*/
  1055. // ---------------------------------------------------------------------
  1056. /* This just verifies that each file in the list of index files exists,
  1057. has matching attributes with the cache and the cache does not have
  1058. any extra files. */
  1059. static bool CheckValidity(const string &CacheFile,
  1060. pkgSourceList &List,
  1061. FileIterator Start,
  1062. FileIterator End,
  1063. MMap **OutMap = 0)
  1064. {
  1065. bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
  1066. // No file, certainly invalid
  1067. if (CacheFile.empty() == true || FileExists(CacheFile) == false)
  1068. {
  1069. if (Debug == true)
  1070. std::clog << "CacheFile doesn't exist" << std::endl;
  1071. return false;
  1072. }
  1073. if (List.GetLastModifiedTime() > GetModificationTime(CacheFile))
  1074. {
  1075. if (Debug == true)
  1076. std::clog << "sources.list is newer than the cache" << std::endl;
  1077. return false;
  1078. }
  1079. // Map it
  1080. FileFd CacheF(CacheFile,FileFd::ReadOnly);
  1081. SPtr<MMap> Map = new MMap(CacheF,0);
  1082. pkgCache Cache(Map);
  1083. if (_error->PendingError() == true || Map->Size() == 0)
  1084. {
  1085. if (Debug == true)
  1086. std::clog << "Errors are pending or Map is empty()" << std::endl;
  1087. _error->Discard();
  1088. return false;
  1089. }
  1090. /* Now we check every index file, see if it is in the cache,
  1091. verify the IMS data and check that it is on the disk too.. */
  1092. SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
  1093. memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
  1094. for (; Start != End; ++Start)
  1095. {
  1096. if (Debug == true)
  1097. std::clog << "Checking PkgFile " << (*Start)->Describe() << ": ";
  1098. if ((*Start)->HasPackages() == false)
  1099. {
  1100. if (Debug == true)
  1101. std::clog << "Has NO packages" << std::endl;
  1102. continue;
  1103. }
  1104. if ((*Start)->Exists() == false)
  1105. {
  1106. #if 0 // mvo: we no longer give a message here (Default Sources spec)
  1107. _error->WarningE("stat",_("Couldn't stat source package list %s"),
  1108. (*Start)->Describe().c_str());
  1109. #endif
  1110. if (Debug == true)
  1111. std::clog << "file doesn't exist" << std::endl;
  1112. continue;
  1113. }
  1114. // FindInCache is also expected to do an IMS check.
  1115. pkgCache::PkgFileIterator File = (*Start)->FindInCache(Cache);
  1116. if (File.end() == true)
  1117. {
  1118. if (Debug == true)
  1119. std::clog << "FindInCache returned end-Pointer" << std::endl;
  1120. return false;
  1121. }
  1122. Visited[File->ID] = true;
  1123. if (Debug == true)
  1124. std::clog << "with ID " << File->ID << " is valid" << std::endl;
  1125. }
  1126. for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++)
  1127. if (Visited[I] == false)
  1128. {
  1129. if (Debug == true)
  1130. std::clog << "File with ID" << I << " wasn't visited" << std::endl;
  1131. return false;
  1132. }
  1133. if (_error->PendingError() == true)
  1134. {
  1135. if (Debug == true)
  1136. {
  1137. std::clog << "Validity failed because of pending errors:" << std::endl;
  1138. _error->DumpErrors();
  1139. }
  1140. _error->Discard();
  1141. return false;
  1142. }
  1143. if (OutMap != 0)
  1144. *OutMap = Map.UnGuard();
  1145. return true;
  1146. }
  1147. /*}}}*/
  1148. // ComputeSize - Compute the total size of a bunch of files /*{{{*/
  1149. // ---------------------------------------------------------------------
  1150. /* Size is kind of an abstract notion that is only used for the progress
  1151. meter */
  1152. static unsigned long ComputeSize(FileIterator Start,FileIterator End)
  1153. {
  1154. unsigned long TotalSize = 0;
  1155. for (; Start < End; ++Start)
  1156. {
  1157. if ((*Start)->HasPackages() == false)
  1158. continue;
  1159. TotalSize += (*Start)->Size();
  1160. }
  1161. return TotalSize;
  1162. }
  1163. /*}}}*/
  1164. // BuildCache - Merge the list of index files into the cache /*{{{*/
  1165. // ---------------------------------------------------------------------
  1166. /* */
  1167. static bool BuildCache(pkgCacheGenerator &Gen,
  1168. OpProgress *Progress,
  1169. unsigned long &CurrentSize,unsigned long TotalSize,
  1170. FileIterator Start, FileIterator End)
  1171. {
  1172. FileIterator I;
  1173. for (I = Start; I != End; ++I)
  1174. {
  1175. if ((*I)->HasPackages() == false)
  1176. continue;
  1177. if ((*I)->Exists() == false)
  1178. continue;
  1179. if ((*I)->FindInCache(Gen.GetCache()).end() == false)
  1180. {
  1181. _error->Warning("Duplicate sources.list entry %s",
  1182. (*I)->Describe().c_str());
  1183. continue;
  1184. }
  1185. unsigned long Size = (*I)->Size();
  1186. if (Progress != NULL)
  1187. Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists"));
  1188. CurrentSize += Size;
  1189. if ((*I)->Merge(Gen,Progress) == false)
  1190. return false;
  1191. }
  1192. if (Gen.HasFileDeps() == true)
  1193. {
  1194. if (Progress != NULL)
  1195. Progress->Done();
  1196. TotalSize = ComputeSize(Start, End);
  1197. CurrentSize = 0;
  1198. for (I = Start; I != End; ++I)
  1199. {
  1200. unsigned long Size = (*I)->Size();
  1201. if (Progress != NULL)
  1202. Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides"));
  1203. CurrentSize += Size;
  1204. if ((*I)->MergeFileProvides(Gen,Progress) == false)
  1205. return false;
  1206. }
  1207. }
  1208. return true;
  1209. }
  1210. /*}}}*/
  1211. // CacheGenerator::CreateDynamicMMap - load an mmap with configuration options /*{{{*/
  1212. DynamicMMap* pkgCacheGenerator::CreateDynamicMMap(FileFd *CacheF, unsigned long Flags) {
  1213. unsigned long const MapStart = _config->FindI("APT::Cache-Start", 24*1024*1024);
  1214. unsigned long const MapGrow = _config->FindI("APT::Cache-Grow", 1*1024*1024);
  1215. unsigned long const MapLimit = _config->FindI("APT::Cache-Limit", 0);
  1216. Flags |= MMap::Moveable;
  1217. if (_config->FindB("APT::Cache-Fallback", false) == true)
  1218. Flags |= MMap::Fallback;
  1219. if (CacheF != NULL)
  1220. return new DynamicMMap(*CacheF, Flags, MapStart, MapGrow, MapLimit);
  1221. else
  1222. return new DynamicMMap(Flags, MapStart, MapGrow, MapLimit);
  1223. }
  1224. /*}}}*/
  1225. // CacheGenerator::MakeStatusCache - Construct the status cache /*{{{*/
  1226. // ---------------------------------------------------------------------
  1227. /* This makes sure that the status cache (the cache that has all
  1228. index files from the sources list and all local ones) is ready
  1229. to be mmaped. If OutMap is not zero then a MMap object representing
  1230. the cache will be stored there. This is pretty much mandetory if you
  1231. are using AllowMem. AllowMem lets the function be run as non-root
  1232. where it builds the cache 'fast' into a memory buffer. */
  1233. APT_DEPRECATED bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  1234. MMap **OutMap, bool AllowMem)
  1235. { return pkgCacheGenerator::MakeStatusCache(List, &Progress, OutMap, AllowMem); }
  1236. bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
  1237. MMap **OutMap,bool AllowMem)
  1238. {
  1239. bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
  1240. std::vector<pkgIndexFile *> Files;
  1241. for (std::vector<metaIndex *>::const_iterator i = List.begin();
  1242. i != List.end();
  1243. ++i)
  1244. {
  1245. std::vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles();
  1246. for (std::vector<pkgIndexFile *>::const_iterator j = Indexes->begin();
  1247. j != Indexes->end();
  1248. ++j)
  1249. Files.push_back (*j);
  1250. }
  1251. unsigned long const EndOfSource = Files.size();
  1252. if (_system->AddStatusFiles(Files) == false)
  1253. return false;
  1254. // Decide if we can write to the files..
  1255. string const CacheFile = _config->FindFile("Dir::Cache::pkgcache");
  1256. string const SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache");
  1257. // ensure the cache directory exists
  1258. if (CacheFile.empty() == false || SrcCacheFile.empty() == false)
  1259. {
  1260. string dir = _config->FindDir("Dir::Cache");
  1261. size_t const len = dir.size();
  1262. if (len > 5 && dir.find("/apt/", len - 6, 5) == len - 5)
  1263. dir = dir.substr(0, len - 5);
  1264. if (CacheFile.empty() == false)
  1265. CreateDirectory(dir, flNotFile(CacheFile));
  1266. if (SrcCacheFile.empty() == false)
  1267. CreateDirectory(dir, flNotFile(SrcCacheFile));
  1268. }
  1269. // Decide if we can write to the cache
  1270. bool Writeable = false;
  1271. if (CacheFile.empty() == false)
  1272. Writeable = access(flNotFile(CacheFile).c_str(),W_OK) == 0;
  1273. else
  1274. if (SrcCacheFile.empty() == false)
  1275. Writeable = access(flNotFile(SrcCacheFile).c_str(),W_OK) == 0;
  1276. if (Debug == true)
  1277. std::clog << "Do we have write-access to the cache files? " << (Writeable ? "YES" : "NO") << std::endl;
  1278. if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
  1279. return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
  1280. if (Progress != NULL)
  1281. Progress->OverallProgress(0,1,1,_("Reading package lists"));
  1282. // Cache is OK, Fin.
  1283. if (CheckValidity(CacheFile, List, Files.begin(),Files.end(),OutMap) == true)
  1284. {
  1285. if (Progress != NULL)
  1286. Progress->OverallProgress(1,1,1,_("Reading package lists"));
  1287. if (Debug == true)
  1288. std::clog << "pkgcache.bin is valid - no need to build anything" << std::endl;
  1289. return true;
  1290. }
  1291. else if (Debug == true)
  1292. std::clog << "pkgcache.bin is NOT valid" << std::endl;
  1293. /* At this point we know we need to reconstruct the package cache,
  1294. begin. */
  1295. SPtr<FileFd> CacheF;
  1296. SPtr<DynamicMMap> Map;
  1297. if (Writeable == true && CacheFile.empty() == false)
  1298. {
  1299. _error->PushToStack();
  1300. unlink(CacheFile.c_str());
  1301. CacheF = new FileFd(CacheFile,FileFd::WriteAtomic);
  1302. fchmod(CacheF->Fd(),0644);
  1303. Map = CreateDynamicMMap(CacheF, MMap::Public);
  1304. if (_error->PendingError() == true)
  1305. {
  1306. delete CacheF.UnGuard();
  1307. delete Map.UnGuard();
  1308. if (Debug == true)
  1309. std::clog << "Open filebased MMap FAILED" << std::endl;
  1310. Writeable = false;
  1311. if (AllowMem == false)
  1312. {
  1313. _error->MergeWithStack();
  1314. return false;
  1315. }
  1316. _error->RevertToStack();
  1317. }
  1318. else
  1319. {
  1320. _error->MergeWithStack();
  1321. if (Debug == true)
  1322. std::clog << "Open filebased MMap" << std::endl;
  1323. }
  1324. }
  1325. if (Writeable == false || CacheFile.empty() == true)
  1326. {
  1327. // Just build it in memory..
  1328. Map = CreateDynamicMMap(NULL);
  1329. if (Debug == true)
  1330. std::clog << "Open memory Map (not filebased)" << std::endl;
  1331. }
  1332. // Lets try the source cache.
  1333. unsigned long CurrentSize = 0;
  1334. unsigned long TotalSize = 0;
  1335. if (CheckValidity(SrcCacheFile, List, Files.begin(),
  1336. Files.begin()+EndOfSource) == true)
  1337. {
  1338. if (Debug == true)
  1339. std::clog << "srcpkgcache.bin is valid - populate MMap with it." << std::endl;
  1340. // Preload the map with the source cache
  1341. FileFd SCacheF(SrcCacheFile,FileFd::ReadOnly);
  1342. unsigned long const alloc = Map->RawAllocate(SCacheF.Size());
  1343. if ((alloc == 0 && _error->PendingError())
  1344. || SCacheF.Read((unsigned char *)Map->Data() + alloc,
  1345. SCacheF.Size()) == false)
  1346. return false;
  1347. TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
  1348. // Build the status cache
  1349. pkgCacheGenerator Gen(Map.Get(),Progress);
  1350. if (_error->PendingError() == true)
  1351. return false;
  1352. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1353. Files.begin()+EndOfSource,Files.end()) == false)
  1354. return false;
  1355. }
  1356. else
  1357. {
  1358. if (Debug == true)
  1359. std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
  1360. TotalSize = ComputeSize(Files.begin(),Files.end());
  1361. // Build the source cache
  1362. pkgCacheGenerator Gen(Map.Get(),Progress);
  1363. if (_error->PendingError() == true)
  1364. return false;
  1365. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1366. Files.begin(),Files.begin()+EndOfSource) == false)
  1367. return false;
  1368. // Write it back
  1369. if (Writeable == true && SrcCacheFile.empty() == false)
  1370. {
  1371. FileFd SCacheF(SrcCacheFile,FileFd::WriteAtomic);
  1372. if (_error->PendingError() == true)
  1373. return false;
  1374. fchmod(SCacheF.Fd(),0644);
  1375. // Write out the main data
  1376. if (SCacheF.Write(Map->Data(),Map->Size()) == false)
  1377. return _error->Error(_("IO Error saving source cache"));
  1378. SCacheF.Sync();
  1379. // Write out the proper header
  1380. Gen.GetCache().HeaderP->Dirty = false;
  1381. if (SCacheF.Seek(0) == false ||
  1382. SCacheF.Write(Map->Data(),sizeof(*Gen.GetCache().HeaderP)) == false)
  1383. return _error->Error(_("IO Error saving source cache"));
  1384. Gen.GetCache().HeaderP->Dirty = true;
  1385. SCacheF.Sync();
  1386. }
  1387. // Build the status cache
  1388. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1389. Files.begin()+EndOfSource,Files.end()) == false)
  1390. return false;
  1391. }
  1392. if (Debug == true)
  1393. std::clog << "Caches are ready for shipping" << std::endl;
  1394. if (_error->PendingError() == true)
  1395. return false;
  1396. if (OutMap != 0)
  1397. {
  1398. if (CacheF != 0)
  1399. {
  1400. delete Map.UnGuard();
  1401. *OutMap = new MMap(*CacheF,0);
  1402. }
  1403. else
  1404. {
  1405. *OutMap = Map.UnGuard();
  1406. }
  1407. }
  1408. return true;
  1409. }
  1410. /*}}}*/
  1411. // CacheGenerator::MakeOnlyStatusCache - Build only a status files cache/*{{{*/
  1412. // ---------------------------------------------------------------------
  1413. /* */
  1414. APT_DEPRECATED bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap)
  1415. { return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); }
  1416. bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap)
  1417. {
  1418. std::vector<pkgIndexFile *> Files;
  1419. unsigned long EndOfSource = Files.size();
  1420. if (_system->AddStatusFiles(Files) == false)
  1421. return false;
  1422. SPtr<DynamicMMap> Map = CreateDynamicMMap(NULL);
  1423. unsigned long CurrentSize = 0;
  1424. unsigned long TotalSize = 0;
  1425. TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
  1426. // Build the status cache
  1427. if (Progress != NULL)
  1428. Progress->OverallProgress(0,1,1,_("Reading package lists"));
  1429. pkgCacheGenerator Gen(Map.Get(),Progress);
  1430. if (_error->PendingError() == true)
  1431. return false;
  1432. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1433. Files.begin()+EndOfSource,Files.end()) == false)
  1434. return false;
  1435. if (_error->PendingError() == true)
  1436. return false;
  1437. *OutMap = Map.UnGuard();
  1438. return true;
  1439. }
  1440. /*}}}*/
  1441. // IsDuplicateDescription /*{{{*/
  1442. static bool IsDuplicateDescription(pkgCache::DescIterator Desc,
  1443. MD5SumValue const &CurMd5, std::string const &CurLang)
  1444. {
  1445. // Descriptions in the same link-list have all the same md5
  1446. if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5)
  1447. return false;
  1448. for (; Desc.end() == false; ++Desc)
  1449. if (Desc.LanguageCode() == CurLang)
  1450. return true;
  1451. return false;
  1452. }
  1453. /*}}}*/
  1454. // CacheGenerator::FinishCache /*{{{*/
  1455. bool pkgCacheGenerator::FinishCache(OpProgress * /*Progress*/)
  1456. {
  1457. return true;
  1458. }
  1459. /*}}}*/