pkgcachegen.cc 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. #define APT_COMPATIBILITY 986
  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/aptconfiguration.h>
  18. #include <apt-pkg/strutl.h>
  19. #include <apt-pkg/sptr.h>
  20. #include <apt-pkg/pkgsystem.h>
  21. #include <apt-pkg/macros.h>
  22. #include <apt-pkg/tagfile.h>
  23. #include <apti18n.h>
  24. #include <vector>
  25. #include <sys/stat.h>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. /*}}}*/
  30. typedef vector<pkgIndexFile *>::iterator FileIterator;
  31. // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
  32. // ---------------------------------------------------------------------
  33. /* We set the dirty flag and make sure that is written to the disk */
  34. pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
  35. Map(*pMap), Cache(pMap,false), Progress(Prog),
  36. FoundFileDeps(0)
  37. {
  38. CurrentFile = 0;
  39. memset(UniqHash,0,sizeof(UniqHash));
  40. if (_error->PendingError() == true)
  41. return;
  42. if (Map.Size() == 0)
  43. {
  44. // Setup the map interface..
  45. Cache.HeaderP = (pkgCache::Header *)Map.Data();
  46. if (Map.RawAllocate(sizeof(pkgCache::Header)) == 0 && _error->PendingError() == true)
  47. return;
  48. Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
  49. // Starting header
  50. *Cache.HeaderP = pkgCache::Header();
  51. Cache.HeaderP->VerSysName = Map.WriteString(_system->VS->Label);
  52. Cache.HeaderP->Architecture = Map.WriteString(_config->Find("APT::Architecture"));
  53. Cache.ReMap();
  54. }
  55. else
  56. {
  57. // Map directly from the existing file
  58. Cache.ReMap();
  59. Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
  60. if (Cache.VS != _system->VS)
  61. {
  62. _error->Error(_("Cache has an incompatible versioning system"));
  63. return;
  64. }
  65. }
  66. Cache.HeaderP->Dirty = true;
  67. Map.Sync(0,sizeof(pkgCache::Header));
  68. }
  69. /*}}}*/
  70. // CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
  71. // ---------------------------------------------------------------------
  72. /* We sync the data then unset the dirty flag in two steps so as to
  73. advoid a problem during a crash */
  74. pkgCacheGenerator::~pkgCacheGenerator()
  75. {
  76. if (_error->PendingError() == true)
  77. return;
  78. if (Map.Sync() == false)
  79. return;
  80. Cache.HeaderP->Dirty = false;
  81. Map.Sync(0,sizeof(pkgCache::Header));
  82. }
  83. /*}}}*/
  84. // CacheGenerator::MergeList - Merge the package list /*{{{*/
  85. // ---------------------------------------------------------------------
  86. /* This provides the generation of the entries in the cache. Each loop
  87. goes through a single package record from the underlying parse engine. */
  88. bool pkgCacheGenerator::MergeList(ListParser &List,
  89. pkgCache::VerIterator *OutVer)
  90. {
  91. List.Owner = this;
  92. unsigned int Counter = 0;
  93. while (List.Step() == true)
  94. {
  95. string const PackageName = List.Package();
  96. if (PackageName.empty() == true)
  97. return false;
  98. /* As we handle Arch all packages as architecture bounded
  99. we add all information to every (simulated) arch package */
  100. std::vector<string> genArch;
  101. if (List.ArchitectureAll() == true) {
  102. genArch = APT::Configuration::getArchitectures();
  103. if (genArch.size() != 1)
  104. genArch.push_back("all");
  105. } else
  106. genArch.push_back(List.Architecture());
  107. for (std::vector<string>::const_iterator arch = genArch.begin();
  108. arch != genArch.end(); ++arch)
  109. {
  110. // Get a pointer to the package structure
  111. pkgCache::PkgIterator Pkg;
  112. if (NewPackage(Pkg, PackageName, *arch) == false)
  113. return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str());
  114. Counter++;
  115. if (Counter % 100 == 0 && Progress != 0)
  116. Progress->Progress(List.Offset());
  117. /* Get a pointer to the version structure. We know the list is sorted
  118. so we use that fact in the search. Insertion of new versions is
  119. done with correct sorting */
  120. string Version = List.Version();
  121. if (Version.empty() == true)
  122. {
  123. // we first process the package, then the descriptions
  124. // (this has the bonus that we get MMap error when we run out
  125. // of MMap space)
  126. if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false)
  127. return _error->Error(_("Error occurred while processing %s (UsePackage1)"),
  128. PackageName.c_str());
  129. // Find the right version to write the description
  130. MD5SumValue CurMd5 = List.Description_md5();
  131. pkgCache::VerIterator Ver = Pkg.VersionList();
  132. map_ptrloc *LastVer = &Pkg->VersionList;
  133. for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++)
  134. {
  135. pkgCache::DescIterator Desc = Ver.DescriptionList();
  136. map_ptrloc *LastDesc = &Ver->DescriptionList;
  137. bool duplicate=false;
  138. // don't add a new description if we have one for the given
  139. // md5 && language
  140. for ( ; Desc.end() == false; Desc++)
  141. if (MD5SumValue(Desc.md5()) == CurMd5 &&
  142. Desc.LanguageCode() == List.DescriptionLanguage())
  143. duplicate=true;
  144. if(duplicate)
  145. continue;
  146. for (Desc = Ver.DescriptionList();
  147. Desc.end() == false;
  148. LastDesc = &Desc->NextDesc, Desc++)
  149. {
  150. if (MD5SumValue(Desc.md5()) == CurMd5)
  151. {
  152. // Add new description
  153. *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc);
  154. Desc->ParentPkg = Pkg.Index();
  155. if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
  156. return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),PackageName.c_str());
  157. break;
  158. }
  159. }
  160. }
  161. continue;
  162. }
  163. pkgCache::VerIterator Ver = Pkg.VersionList();
  164. map_ptrloc *LastVer = &Pkg->VersionList;
  165. int Res = 1;
  166. unsigned long const Hash = List.VersionHash();
  167. for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++)
  168. {
  169. Res = Cache.VS->CmpVersion(Version,Ver.VerStr());
  170. // Version is higher as current version - insert here
  171. if (Res > 0)
  172. break;
  173. // Versionstrings are equal - is hash also equal?
  174. if (Res == 0 && Ver->Hash == Hash)
  175. break;
  176. // proceed with the next till we have either the right
  177. // or we found another version (which will be lower)
  178. }
  179. /* We already have a version for this item, record that we saw it */
  180. if (Res == 0 && Ver.end() == false && Ver->Hash == Hash)
  181. {
  182. if (List.UsePackage(Pkg,Ver) == false)
  183. return _error->Error(_("Error occurred while processing %s (UsePackage2)"),
  184. PackageName.c_str());
  185. if (NewFileVer(Ver,List) == false)
  186. return _error->Error(_("Error occurred while processing %s (NewFileVer1)"),
  187. PackageName.c_str());
  188. // Read only a single record and return
  189. if (OutVer != 0)
  190. {
  191. *OutVer = Ver;
  192. FoundFileDeps |= List.HasFileDeps();
  193. return true;
  194. }
  195. continue;
  196. }
  197. // Add a new version
  198. *LastVer = NewVersion(Ver,Version,*LastVer);
  199. Ver->ParentPkg = Pkg.Index();
  200. Ver->Hash = Hash;
  201. if ((*LastVer == 0 && _error->PendingError()) || List.NewVersion(Ver) == false)
  202. return _error->Error(_("Error occurred while processing %s (NewVersion1)"),
  203. PackageName.c_str());
  204. if (List.UsePackage(Pkg,Ver) == false)
  205. return _error->Error(_("Error occurred while processing %s (UsePackage3)"),
  206. PackageName.c_str());
  207. if (NewFileVer(Ver,List) == false)
  208. return _error->Error(_("Error occurred while processing %s (NewVersion2)"),
  209. PackageName.c_str());
  210. // Read only a single record and return
  211. if (OutVer != 0)
  212. {
  213. *OutVer = Ver;
  214. FoundFileDeps |= List.HasFileDeps();
  215. return true;
  216. }
  217. /* Record the Description data. Description data always exist in
  218. Packages and Translation-* files. */
  219. pkgCache::DescIterator Desc = Ver.DescriptionList();
  220. map_ptrloc *LastDesc = &Ver->DescriptionList;
  221. // Skip to the end of description set
  222. for (; Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++);
  223. // Add new description
  224. *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), List.Description_md5(), *LastDesc);
  225. Desc->ParentPkg = Pkg.Index();
  226. if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
  227. return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str());
  228. }
  229. }
  230. FoundFileDeps |= List.HasFileDeps();
  231. if (Cache.HeaderP->PackageCount >= (1ULL<<sizeof(Cache.PkgP->ID)*8)-1)
  232. return _error->Error(_("Wow, you exceeded the number of package "
  233. "names this APT is capable of."));
  234. if (Cache.HeaderP->VersionCount >= (1ULL<<(sizeof(Cache.VerP->ID)*8))-1)
  235. return _error->Error(_("Wow, you exceeded the number of versions "
  236. "this APT is capable of."));
  237. if (Cache.HeaderP->DescriptionCount >= (1ULL<<(sizeof(Cache.DescP->ID)*8))-1)
  238. return _error->Error(_("Wow, you exceeded the number of descriptions "
  239. "this APT is capable of."));
  240. if (Cache.HeaderP->DependsCount >= (1ULL<<(sizeof(Cache.DepP->ID)*8))-1ULL)
  241. return _error->Error(_("Wow, you exceeded the number of dependencies "
  242. "this APT is capable of."));
  243. return true;
  244. }
  245. /*}}}*/
  246. // CacheGenerator::MergeFileProvides - Merge file provides /*{{{*/
  247. // ---------------------------------------------------------------------
  248. /* If we found any file depends while parsing the main list we need to
  249. resolve them. Since it is undesired to load the entire list of files
  250. into the cache as virtual packages we do a two stage effort. MergeList
  251. identifies the file depends and this creates Provdies for them by
  252. re-parsing all the indexs. */
  253. bool pkgCacheGenerator::MergeFileProvides(ListParser &List)
  254. {
  255. List.Owner = this;
  256. unsigned int Counter = 0;
  257. while (List.Step() == true)
  258. {
  259. string PackageName = List.Package();
  260. if (PackageName.empty() == true)
  261. return false;
  262. string Version = List.Version();
  263. if (Version.empty() == true)
  264. continue;
  265. pkgCache::PkgIterator Pkg = Cache.FindPkg(PackageName);
  266. if (Pkg.end() == true)
  267. return _error->Error(_("Error occurred while processing %s (FindPkg)"),
  268. PackageName.c_str());
  269. Counter++;
  270. if (Counter % 100 == 0 && Progress != 0)
  271. Progress->Progress(List.Offset());
  272. unsigned long Hash = List.VersionHash();
  273. pkgCache::VerIterator Ver = Pkg.VersionList();
  274. for (; Ver.end() == false; Ver++)
  275. {
  276. if (Ver->Hash == Hash && Version.c_str() == Ver.VerStr())
  277. {
  278. if (List.CollectFileProvides(Cache,Ver) == false)
  279. return _error->Error(_("Error occurred while processing %s (CollectFileProvides)"),PackageName.c_str());
  280. break;
  281. }
  282. }
  283. if (Ver.end() == true)
  284. _error->Warning(_("Package %s %s was not found while processing file dependencies"),PackageName.c_str(),Version.c_str());
  285. }
  286. return true;
  287. }
  288. /*}}}*/
  289. // CacheGenerator::NewGroup - Add a new group /*{{{*/
  290. // ---------------------------------------------------------------------
  291. /* This creates a new group structure and adds it to the hash table */
  292. bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
  293. {
  294. Grp = Cache.FindGrp(Name);
  295. if (Grp.end() == false)
  296. return true;
  297. // Get a structure
  298. unsigned long const Group = Map.Allocate(sizeof(pkgCache::Group));
  299. if (unlikely(Group == 0))
  300. return false;
  301. Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group);
  302. Grp->Name = Map.WriteString(Name);
  303. if (unlikely(Grp->Name == 0))
  304. return false;
  305. // Insert it into the hash table
  306. unsigned long const Hash = Cache.Hash(Name);
  307. Grp->Next = Cache.HeaderP->GrpHashTable[Hash];
  308. Cache.HeaderP->GrpHashTable[Hash] = Group;
  309. Grp->ID = Cache.HeaderP->GroupCount++;
  310. return true;
  311. }
  312. /*}}}*/
  313. // CacheGenerator::NewPackage - Add a new package /*{{{*/
  314. // ---------------------------------------------------------------------
  315. /* This creates a new package structure and adds it to the hash table */
  316. bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name,
  317. const string &Arch) {
  318. pkgCache::GrpIterator Grp;
  319. if (unlikely(NewGroup(Grp, Name) == false))
  320. return false;
  321. Pkg = Grp.FindPkg(Arch);
  322. if (Pkg.end() == false)
  323. return true;
  324. // Get a structure
  325. unsigned long const Package = Map.Allocate(sizeof(pkgCache::Package));
  326. if (unlikely(Package == 0))
  327. return false;
  328. Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package);
  329. // Insert the package into our package list
  330. if (Grp->FirstPackage == 0) // the group is new
  331. {
  332. // Insert it into the hash table
  333. unsigned long const Hash = Cache.Hash(Name);
  334. Pkg->NextPackage = Cache.HeaderP->PkgHashTable[Hash];
  335. Cache.HeaderP->PkgHashTable[Hash] = Package;
  336. Grp->FirstPackage = Package;
  337. }
  338. else // Group the Packages together
  339. {
  340. // this package is the new last package
  341. pkgCache::PkgIterator LastPkg(Cache, Cache.PkgP + Grp->LastPackage);
  342. Pkg->NextPackage = LastPkg->NextPackage;
  343. LastPkg->NextPackage = Package;
  344. }
  345. Grp->LastPackage = Package;
  346. // Set the name, arch and the ID
  347. Pkg->Name = Grp->Name;
  348. Pkg->Group = Grp.Index();
  349. Pkg->Arch = WriteUniqString(Arch.c_str());
  350. if (unlikely(Pkg->Arch == 0))
  351. return false;
  352. Pkg->ID = Cache.HeaderP->PackageCount++;
  353. return true;
  354. }
  355. /*}}}*/
  356. // CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
  357. // ---------------------------------------------------------------------
  358. /* */
  359. bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
  360. ListParser &List)
  361. {
  362. if (CurrentFile == 0)
  363. return true;
  364. // Get a structure
  365. unsigned long VerFile = Map.Allocate(sizeof(pkgCache::VerFile));
  366. if (VerFile == 0)
  367. return 0;
  368. pkgCache::VerFileIterator VF(Cache,Cache.VerFileP + VerFile);
  369. VF->File = CurrentFile - Cache.PkgFileP;
  370. // Link it to the end of the list
  371. map_ptrloc *Last = &Ver->FileList;
  372. for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; V++)
  373. Last = &V->NextFile;
  374. VF->NextFile = *Last;
  375. *Last = VF.Index();
  376. VF->Offset = List.Offset();
  377. VF->Size = List.Size();
  378. if (Cache.HeaderP->MaxVerFileSize < VF->Size)
  379. Cache.HeaderP->MaxVerFileSize = VF->Size;
  380. Cache.HeaderP->VerFileCount++;
  381. return true;
  382. }
  383. /*}}}*/
  384. // CacheGenerator::NewVersion - Create a new Version /*{{{*/
  385. // ---------------------------------------------------------------------
  386. /* This puts a version structure in the linked list */
  387. unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
  388. const string &VerStr,
  389. unsigned long Next)
  390. {
  391. // Get a structure
  392. unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
  393. if (Version == 0)
  394. return 0;
  395. // Fill it in
  396. Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
  397. Ver->NextVer = Next;
  398. Ver->ID = Cache.HeaderP->VersionCount++;
  399. Ver->VerStr = Map.WriteString(VerStr);
  400. if (Ver->VerStr == 0)
  401. return 0;
  402. return Version;
  403. }
  404. /*}}}*/
  405. // CacheGenerator::NewFileDesc - Create a new File<->Desc association /*{{{*/
  406. // ---------------------------------------------------------------------
  407. /* */
  408. bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc,
  409. ListParser &List)
  410. {
  411. if (CurrentFile == 0)
  412. return true;
  413. // Get a structure
  414. unsigned long DescFile = Map.Allocate(sizeof(pkgCache::DescFile));
  415. if (DescFile == 0)
  416. return false;
  417. pkgCache::DescFileIterator DF(Cache,Cache.DescFileP + DescFile);
  418. DF->File = CurrentFile - Cache.PkgFileP;
  419. // Link it to the end of the list
  420. map_ptrloc *Last = &Desc->FileList;
  421. for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; D++)
  422. Last = &D->NextFile;
  423. DF->NextFile = *Last;
  424. *Last = DF.Index();
  425. DF->Offset = List.Offset();
  426. DF->Size = List.Size();
  427. if (Cache.HeaderP->MaxDescFileSize < DF->Size)
  428. Cache.HeaderP->MaxDescFileSize = DF->Size;
  429. Cache.HeaderP->DescFileCount++;
  430. return true;
  431. }
  432. /*}}}*/
  433. // CacheGenerator::NewDescription - Create a new Description /*{{{*/
  434. // ---------------------------------------------------------------------
  435. /* This puts a description structure in the linked list */
  436. map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc,
  437. const string &Lang,
  438. const MD5SumValue &md5sum,
  439. map_ptrloc Next)
  440. {
  441. // Get a structure
  442. map_ptrloc Description = Map.Allocate(sizeof(pkgCache::Description));
  443. if (Description == 0)
  444. return 0;
  445. // Fill it in
  446. Desc = pkgCache::DescIterator(Cache,Cache.DescP + Description);
  447. Desc->NextDesc = Next;
  448. Desc->ID = Cache.HeaderP->DescriptionCount++;
  449. Desc->language_code = Map.WriteString(Lang);
  450. Desc->md5sum = Map.WriteString(md5sum.Value());
  451. if (Desc->language_code == 0 || Desc->md5sum == 0)
  452. return 0;
  453. return Description;
  454. }
  455. /*}}}*/
  456. // CacheGenerator::FinishCache - do various finish operations /*{{{*/
  457. // ---------------------------------------------------------------------
  458. /* This prepares the Cache for delivery */
  459. bool pkgCacheGenerator::FinishCache(OpProgress &Progress)
  460. {
  461. // FIXME: add progress reporting for this operation
  462. // Do we have different architectures in your groups ?
  463. vector<string> archs = APT::Configuration::getArchitectures();
  464. if (archs.size() > 1)
  465. {
  466. // Create Conflicts in between the group
  467. for (pkgCache::GrpIterator G = GetCache().GrpBegin(); G.end() != true; G++)
  468. {
  469. string const PkgName = G.Name();
  470. for (pkgCache::PkgIterator P = G.PackageList(); P.end() != true; P = G.NextPkg(P))
  471. {
  472. if (strcmp(P.Arch(),"all") == 0)
  473. continue;
  474. pkgCache::PkgIterator allPkg;
  475. for (pkgCache::VerIterator V = P.VersionList(); V.end() != true; V++)
  476. {
  477. string const Arch = V.Arch(true);
  478. map_ptrloc *OldDepLast = NULL;
  479. /* MultiArch handling introduces a lot of implicit Dependencies:
  480. - MultiArch: same → Co-Installable if they have the same version
  481. - Architecture: all → Need to be Co-Installable for internal reasons
  482. - All others conflict with all other group members */
  483. bool const coInstall = (V->MultiArch == pkgCache::Version::All ||
  484. V->MultiArch == pkgCache::Version::Same);
  485. if (V->MultiArch == pkgCache::Version::All && allPkg.end() == true)
  486. allPkg = G.FindPkg("all");
  487. for (vector<string>::const_iterator A = archs.begin(); A != archs.end(); ++A)
  488. {
  489. if (*A == Arch)
  490. continue;
  491. /* We allow only one installed arch at the time
  492. per group, therefore each group member conflicts
  493. with all other group members */
  494. pkgCache::PkgIterator D = G.FindPkg(*A);
  495. if (D.end() == true)
  496. continue;
  497. if (coInstall == true)
  498. {
  499. // Replaces: ${self}:other ( << ${binary:Version})
  500. NewDepends(D, V, V.VerStr(),
  501. pkgCache::Dep::Less, pkgCache::Dep::Replaces,
  502. OldDepLast);
  503. // Breaks: ${self}:other (!= ${binary:Version})
  504. NewDepends(D, V, V.VerStr(),
  505. pkgCache::Dep::Less, pkgCache::Dep::DpkgBreaks,
  506. OldDepLast);
  507. NewDepends(D, V, V.VerStr(),
  508. pkgCache::Dep::Greater, pkgCache::Dep::DpkgBreaks,
  509. OldDepLast);
  510. if (V->MultiArch == pkgCache::Version::All)
  511. {
  512. // Depend on ${self}:all which does depend on nothing
  513. NewDepends(allPkg, V, V.VerStr(),
  514. pkgCache::Dep::Equals, pkgCache::Dep::Depends,
  515. OldDepLast);
  516. }
  517. } else {
  518. // Conflicts: ${self}:other
  519. NewDepends(D, V, "",
  520. pkgCache::Dep::NoOp, pkgCache::Dep::Conflicts,
  521. OldDepLast);
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }
  528. return true;
  529. }
  530. /*}}}*/
  531. // CacheGenerator::NewDepends - Create a dependency element /*{{{*/
  532. // ---------------------------------------------------------------------
  533. /* This creates a dependency element in the tree. It is linked to the
  534. version and to the package that it is pointing to. */
  535. bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
  536. pkgCache::VerIterator &Ver,
  537. string const &Version,
  538. unsigned int const &Op,
  539. unsigned int const &Type,
  540. map_ptrloc *OldDepLast)
  541. {
  542. // Get a structure
  543. unsigned long const Dependency = Map.Allocate(sizeof(pkgCache::Dependency));
  544. if (unlikely(Dependency == 0))
  545. return false;
  546. // Fill it in
  547. pkgCache::DepIterator Dep(Cache,Cache.DepP + Dependency);
  548. Dep->ParentVer = Ver.Index();
  549. Dep->Type = Type;
  550. Dep->CompareOp = Op;
  551. Dep->ID = Cache.HeaderP->DependsCount++;
  552. // Probe the reverse dependency list for a version string that matches
  553. if (Version.empty() == false)
  554. {
  555. /* for (pkgCache::DepIterator I = Pkg.RevDependsList(); I.end() == false; I++)
  556. if (I->Version != 0 && I.TargetVer() == Version)
  557. Dep->Version = I->Version;*/
  558. if (Dep->Version == 0)
  559. if (unlikely((Dep->Version = Map.WriteString(Version)) == 0))
  560. return false;
  561. }
  562. // Link it to the package
  563. Dep->Package = Pkg.Index();
  564. Dep->NextRevDepends = Pkg->RevDepends;
  565. Pkg->RevDepends = Dep.Index();
  566. // Do we know where to link the Dependency to?
  567. if (OldDepLast == NULL)
  568. {
  569. OldDepLast = &Ver->DependsList;
  570. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  571. OldDepLast = &D->NextDepends;
  572. }
  573. Dep->NextDepends = *OldDepLast;
  574. *OldDepLast = Dep.Index();
  575. OldDepLast = &Dep->NextDepends;
  576. return true;
  577. }
  578. /*}}}*/
  579. // ListParser::NewDepends - Create the environment for a new dependency /*{{{*/
  580. // ---------------------------------------------------------------------
  581. /* This creates a Group and the Package to link this dependency to if
  582. needed and handles also the caching of the old endpoint */
  583. bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver,
  584. const string &PackageName,
  585. const string &Arch,
  586. const string &Version,
  587. unsigned int Op,
  588. unsigned int Type)
  589. {
  590. pkgCache::GrpIterator Grp;
  591. if (unlikely(Owner->NewGroup(Grp, PackageName) == false))
  592. return false;
  593. // Locate the target package
  594. pkgCache::PkgIterator Pkg = Grp.FindPkg(Arch);
  595. if (Pkg.end() == true) {
  596. if (unlikely(Owner->NewPackage(Pkg, PackageName, Arch) == false))
  597. return false;
  598. }
  599. // Is it a file dependency?
  600. if (unlikely(PackageName[0] == '/'))
  601. FoundFileDeps = true;
  602. /* Caching the old end point speeds up generation substantially */
  603. if (OldDepVer != Ver) {
  604. OldDepLast = NULL;
  605. OldDepVer = Ver;
  606. }
  607. return Owner->NewDepends(Pkg, Ver, Version, Op, Type, OldDepLast);
  608. }
  609. /*}}}*/
  610. // ListParser::NewProvides - Create a Provides element /*{{{*/
  611. // ---------------------------------------------------------------------
  612. /* */
  613. bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver,
  614. const string &PkgName,
  615. const string &PkgArch,
  616. const string &Version)
  617. {
  618. pkgCache &Cache = Owner->Cache;
  619. // We do not add self referencing provides
  620. if (Ver.ParentPkg().Name() == PkgName && PkgArch == Ver.Arch(true))
  621. return true;
  622. // Get a structure
  623. unsigned long const Provides = Owner->Map.Allocate(sizeof(pkgCache::Provides));
  624. if (unlikely(Provides == 0))
  625. return false;
  626. Cache.HeaderP->ProvidesCount++;
  627. // Fill it in
  628. pkgCache::PrvIterator Prv(Cache,Cache.ProvideP + Provides,Cache.PkgP);
  629. Prv->Version = Ver.Index();
  630. Prv->NextPkgProv = Ver->ProvidesList;
  631. Ver->ProvidesList = Prv.Index();
  632. if (Version.empty() == false && unlikely((Prv->ProvideVersion = WriteString(Version)) == 0))
  633. return false;
  634. // Locate the target package
  635. pkgCache::PkgIterator Pkg;
  636. if (unlikely(Owner->NewPackage(Pkg,PkgName, PkgArch) == false))
  637. return false;
  638. // Link it to the package
  639. Prv->ParentPkg = Pkg.Index();
  640. Prv->NextProvides = Pkg->ProvidesList;
  641. Pkg->ProvidesList = Prv.Index();
  642. return true;
  643. }
  644. /*}}}*/
  645. // CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
  646. // ---------------------------------------------------------------------
  647. /* This is used to select which file is to be associated with all newly
  648. added versions. The caller is responsible for setting the IMS fields. */
  649. bool pkgCacheGenerator::SelectFile(const string &File,const string &Site,
  650. const pkgIndexFile &Index,
  651. unsigned long Flags)
  652. {
  653. // Get some space for the structure
  654. CurrentFile = Cache.PkgFileP + Map.Allocate(sizeof(*CurrentFile));
  655. if (CurrentFile == Cache.PkgFileP)
  656. return false;
  657. // Fill it in
  658. CurrentFile->FileName = Map.WriteString(File);
  659. CurrentFile->Site = WriteUniqString(Site);
  660. CurrentFile->NextFile = Cache.HeaderP->FileList;
  661. CurrentFile->Flags = Flags;
  662. CurrentFile->ID = Cache.HeaderP->PackageFileCount;
  663. CurrentFile->IndexType = WriteUniqString(Index.GetType()->Label);
  664. PkgFileName = File;
  665. Cache.HeaderP->FileList = CurrentFile - Cache.PkgFileP;
  666. Cache.HeaderP->PackageFileCount++;
  667. if (CurrentFile->FileName == 0)
  668. return false;
  669. if (Progress != 0)
  670. Progress->SubProgress(Index.Size());
  671. return true;
  672. }
  673. /*}}}*/
  674. // CacheGenerator::WriteUniqueString - Insert a unique string /*{{{*/
  675. // ---------------------------------------------------------------------
  676. /* This is used to create handles to strings. Given the same text it
  677. always returns the same number */
  678. unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
  679. unsigned int Size)
  680. {
  681. /* We use a very small transient hash table here, this speeds up generation
  682. by a fair amount on slower machines */
  683. pkgCache::StringItem *&Bucket = UniqHash[(S[0]*5 + S[1]) % _count(UniqHash)];
  684. if (Bucket != 0 &&
  685. stringcmp(S,S+Size,Cache.StrP + Bucket->String) == 0)
  686. return Bucket->String;
  687. // Search for an insertion point
  688. pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList;
  689. int Res = 1;
  690. map_ptrloc *Last = &Cache.HeaderP->StringList;
  691. for (; I != Cache.StringItemP; Last = &I->NextItem,
  692. I = Cache.StringItemP + I->NextItem)
  693. {
  694. Res = stringcmp(S,S+Size,Cache.StrP + I->String);
  695. if (Res >= 0)
  696. break;
  697. }
  698. // Match
  699. if (Res == 0)
  700. {
  701. Bucket = I;
  702. return I->String;
  703. }
  704. // Get a structure
  705. unsigned long Item = Map.Allocate(sizeof(pkgCache::StringItem));
  706. if (Item == 0)
  707. return 0;
  708. // Fill in the structure
  709. pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
  710. ItemP->NextItem = I - Cache.StringItemP;
  711. *Last = Item;
  712. ItemP->String = Map.WriteString(S,Size);
  713. if (ItemP->String == 0)
  714. return 0;
  715. Bucket = ItemP;
  716. return ItemP->String;
  717. }
  718. /*}}}*/
  719. // CheckValidity - Check that a cache is up-to-date /*{{{*/
  720. // ---------------------------------------------------------------------
  721. /* This just verifies that each file in the list of index files exists,
  722. has matching attributes with the cache and the cache does not have
  723. any extra files. */
  724. static bool CheckValidity(const string &CacheFile, FileIterator Start,
  725. FileIterator End,MMap **OutMap = 0)
  726. {
  727. bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
  728. // No file, certainly invalid
  729. if (CacheFile.empty() == true || FileExists(CacheFile) == false)
  730. {
  731. if (Debug == true)
  732. std::clog << "CacheFile doesn't exist" << std::endl;
  733. return false;
  734. }
  735. // Map it
  736. FileFd CacheF(CacheFile,FileFd::ReadOnly);
  737. SPtr<MMap> Map = new MMap(CacheF,0);
  738. pkgCache Cache(Map);
  739. if (_error->PendingError() == true || Map->Size() == 0)
  740. {
  741. if (Debug == true)
  742. std::clog << "Errors are pending or Map is empty()" << std::endl;
  743. _error->Discard();
  744. return false;
  745. }
  746. /* Now we check every index file, see if it is in the cache,
  747. verify the IMS data and check that it is on the disk too.. */
  748. SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
  749. memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
  750. for (; Start != End; Start++)
  751. {
  752. if (Debug == true)
  753. std::clog << "Checking PkgFile " << (*Start)->Describe() << ": ";
  754. if ((*Start)->HasPackages() == false)
  755. {
  756. if (Debug == true)
  757. std::clog << "Has NO packages" << std::endl;
  758. continue;
  759. }
  760. if ((*Start)->Exists() == false)
  761. {
  762. #if 0 // mvo: we no longer give a message here (Default Sources spec)
  763. _error->WarningE("stat",_("Couldn't stat source package list %s"),
  764. (*Start)->Describe().c_str());
  765. #endif
  766. if (Debug == true)
  767. std::clog << "file doesn't exist" << std::endl;
  768. continue;
  769. }
  770. // FindInCache is also expected to do an IMS check.
  771. pkgCache::PkgFileIterator File = (*Start)->FindInCache(Cache);
  772. if (File.end() == true)
  773. {
  774. if (Debug == true)
  775. std::clog << "FindInCache returned end-Pointer" << std::endl;
  776. return false;
  777. }
  778. Visited[File->ID] = true;
  779. if (Debug == true)
  780. std::clog << "with ID " << File->ID << " is valid" << std::endl;
  781. }
  782. for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++)
  783. if (Visited[I] == false)
  784. {
  785. if (Debug == true)
  786. std::clog << "File with ID" << I << " wasn't visited" << std::endl;
  787. return false;
  788. }
  789. if (_error->PendingError() == true)
  790. {
  791. if (Debug == true)
  792. {
  793. std::clog << "Validity failed because of pending errors:" << std::endl;
  794. _error->DumpErrors();
  795. }
  796. _error->Discard();
  797. return false;
  798. }
  799. if (OutMap != 0)
  800. *OutMap = Map.UnGuard();
  801. return true;
  802. }
  803. /*}}}*/
  804. // ComputeSize - Compute the total size of a bunch of files /*{{{*/
  805. // ---------------------------------------------------------------------
  806. /* Size is kind of an abstract notion that is only used for the progress
  807. meter */
  808. static unsigned long ComputeSize(FileIterator Start,FileIterator End)
  809. {
  810. unsigned long TotalSize = 0;
  811. for (; Start != End; Start++)
  812. {
  813. if ((*Start)->HasPackages() == false)
  814. continue;
  815. TotalSize += (*Start)->Size();
  816. }
  817. return TotalSize;
  818. }
  819. /*}}}*/
  820. // BuildCache - Merge the list of index files into the cache /*{{{*/
  821. // ---------------------------------------------------------------------
  822. /* */
  823. static bool BuildCache(pkgCacheGenerator &Gen,
  824. OpProgress &Progress,
  825. unsigned long &CurrentSize,unsigned long TotalSize,
  826. FileIterator Start, FileIterator End)
  827. {
  828. FileIterator I;
  829. for (I = Start; I != End; I++)
  830. {
  831. if ((*I)->HasPackages() == false)
  832. continue;
  833. if ((*I)->Exists() == false)
  834. continue;
  835. if ((*I)->FindInCache(Gen.GetCache()).end() == false)
  836. {
  837. _error->Warning("Duplicate sources.list entry %s",
  838. (*I)->Describe().c_str());
  839. continue;
  840. }
  841. unsigned long Size = (*I)->Size();
  842. Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists"));
  843. CurrentSize += Size;
  844. if ((*I)->Merge(Gen,Progress) == false)
  845. return false;
  846. }
  847. if (Gen.HasFileDeps() == true)
  848. {
  849. Progress.Done();
  850. TotalSize = ComputeSize(Start, End);
  851. CurrentSize = 0;
  852. for (I = Start; I != End; I++)
  853. {
  854. unsigned long Size = (*I)->Size();
  855. Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides"));
  856. CurrentSize += Size;
  857. if ((*I)->MergeFileProvides(Gen,Progress) == false)
  858. return false;
  859. }
  860. }
  861. return true;
  862. }
  863. /*}}}*/
  864. // MakeStatusCache - Construct the status cache /*{{{*/
  865. // ---------------------------------------------------------------------
  866. /* This makes sure that the status cache (the cache that has all
  867. index files from the sources list and all local ones) is ready
  868. to be mmaped. If OutMap is not zero then a MMap object representing
  869. the cache will be stored there. This is pretty much mandetory if you
  870. are using AllowMem. AllowMem lets the function be run as non-root
  871. where it builds the cache 'fast' into a memory buffer. */
  872. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  873. MMap **OutMap,bool AllowMem)
  874. {
  875. bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
  876. unsigned long const MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024);
  877. vector<pkgIndexFile *> Files;
  878. for (vector<metaIndex *>::const_iterator i = List.begin();
  879. i != List.end();
  880. i++)
  881. {
  882. vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles();
  883. for (vector<pkgIndexFile *>::const_iterator j = Indexes->begin();
  884. j != Indexes->end();
  885. j++)
  886. Files.push_back (*j);
  887. }
  888. unsigned long const EndOfSource = Files.size();
  889. if (_system->AddStatusFiles(Files) == false)
  890. return false;
  891. // Decide if we can write to the files..
  892. string const CacheFile = _config->FindFile("Dir::Cache::pkgcache");
  893. string const SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache");
  894. // ensure the cache directory exists
  895. if (CacheFile.empty() == false || SrcCacheFile.empty() == false)
  896. {
  897. string dir = _config->FindDir("Dir::Cache");
  898. size_t const len = dir.size();
  899. if (len > 5 && dir.find("/apt/", len - 6, 5) == len - 5)
  900. dir = dir.substr(0, len - 5);
  901. if (CacheFile.empty() == false)
  902. CreateDirectory(dir, flNotFile(CacheFile));
  903. if (SrcCacheFile.empty() == false)
  904. CreateDirectory(dir, flNotFile(SrcCacheFile));
  905. }
  906. // Decide if we can write to the cache
  907. bool Writeable = false;
  908. if (CacheFile.empty() == false)
  909. Writeable = access(flNotFile(CacheFile).c_str(),W_OK) == 0;
  910. else
  911. if (SrcCacheFile.empty() == false)
  912. Writeable = access(flNotFile(SrcCacheFile).c_str(),W_OK) == 0;
  913. if (Debug == true)
  914. std::clog << "Do we have write-access to the cache files? " << (Writeable ? "YES" : "NO") << std::endl;
  915. if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
  916. return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
  917. Progress.OverallProgress(0,1,1,_("Reading package lists"));
  918. // Cache is OK, Fin.
  919. if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
  920. {
  921. Progress.OverallProgress(1,1,1,_("Reading package lists"));
  922. if (Debug == true)
  923. std::clog << "pkgcache.bin is valid - no need to build anything" << std::endl;
  924. return true;
  925. }
  926. else if (Debug == true)
  927. std::clog << "pkgcache.bin is NOT valid" << std::endl;
  928. /* At this point we know we need to reconstruct the package cache,
  929. begin. */
  930. SPtr<FileFd> CacheF;
  931. SPtr<DynamicMMap> Map;
  932. if (Writeable == true && CacheFile.empty() == false)
  933. {
  934. unlink(CacheFile.c_str());
  935. CacheF = new FileFd(CacheFile,FileFd::WriteEmpty);
  936. fchmod(CacheF->Fd(),0644);
  937. Map = new DynamicMMap(*CacheF,MMap::Public,MapSize);
  938. if (_error->PendingError() == true)
  939. return false;
  940. if (Debug == true)
  941. std::clog << "Open filebased MMap" << std::endl;
  942. }
  943. else
  944. {
  945. // Just build it in memory..
  946. Map = new DynamicMMap(0,MapSize);
  947. if (Debug == true)
  948. std::clog << "Open memory Map (not filebased)" << std::endl;
  949. }
  950. // Lets try the source cache.
  951. unsigned long CurrentSize = 0;
  952. unsigned long TotalSize = 0;
  953. if (CheckValidity(SrcCacheFile,Files.begin(),
  954. Files.begin()+EndOfSource) == true)
  955. {
  956. if (Debug == true)
  957. std::clog << "srcpkgcache.bin is valid - populate MMap with it." << std::endl;
  958. // Preload the map with the source cache
  959. FileFd SCacheF(SrcCacheFile,FileFd::ReadOnly);
  960. unsigned long const alloc = Map->RawAllocate(SCacheF.Size());
  961. if ((alloc == 0 && _error->PendingError())
  962. || SCacheF.Read((unsigned char *)Map->Data() + alloc,
  963. SCacheF.Size()) == false)
  964. return false;
  965. TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
  966. // Build the status cache
  967. pkgCacheGenerator Gen(Map.Get(),&Progress);
  968. if (_error->PendingError() == true)
  969. return false;
  970. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  971. Files.begin()+EndOfSource,Files.end()) == false)
  972. return false;
  973. // FIXME: move me to a better place
  974. Gen.FinishCache(Progress);
  975. }
  976. else
  977. {
  978. if (Debug == true)
  979. std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
  980. TotalSize = ComputeSize(Files.begin(),Files.end());
  981. // Build the source cache
  982. pkgCacheGenerator Gen(Map.Get(),&Progress);
  983. if (_error->PendingError() == true)
  984. return false;
  985. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  986. Files.begin(),Files.begin()+EndOfSource) == false)
  987. return false;
  988. // Write it back
  989. if (Writeable == true && SrcCacheFile.empty() == false)
  990. {
  991. FileFd SCacheF(SrcCacheFile,FileFd::WriteEmpty);
  992. if (_error->PendingError() == true)
  993. return false;
  994. fchmod(SCacheF.Fd(),0644);
  995. // Write out the main data
  996. if (SCacheF.Write(Map->Data(),Map->Size()) == false)
  997. return _error->Error(_("IO Error saving source cache"));
  998. SCacheF.Sync();
  999. // Write out the proper header
  1000. Gen.GetCache().HeaderP->Dirty = false;
  1001. if (SCacheF.Seek(0) == false ||
  1002. SCacheF.Write(Map->Data(),sizeof(*Gen.GetCache().HeaderP)) == false)
  1003. return _error->Error(_("IO Error saving source cache"));
  1004. Gen.GetCache().HeaderP->Dirty = true;
  1005. SCacheF.Sync();
  1006. }
  1007. // Build the status cache
  1008. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1009. Files.begin()+EndOfSource,Files.end()) == false)
  1010. return false;
  1011. // FIXME: move me to a better place
  1012. Gen.FinishCache(Progress);
  1013. }
  1014. if (Debug == true)
  1015. std::clog << "Caches are ready for shipping" << std::endl;
  1016. if (_error->PendingError() == true)
  1017. return false;
  1018. if (OutMap != 0)
  1019. {
  1020. if (CacheF != 0)
  1021. {
  1022. delete Map.UnGuard();
  1023. *OutMap = new MMap(*CacheF,0);
  1024. }
  1025. else
  1026. {
  1027. *OutMap = Map.UnGuard();
  1028. }
  1029. }
  1030. return true;
  1031. }
  1032. /*}}}*/
  1033. // MakeOnlyStatusCache - Build a cache with just the status files /*{{{*/
  1034. // ---------------------------------------------------------------------
  1035. /* */
  1036. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap)
  1037. {
  1038. unsigned long MapSize = _config->FindI("APT::Cache-Limit",20*1024*1024);
  1039. vector<pkgIndexFile *> Files;
  1040. unsigned long EndOfSource = Files.size();
  1041. if (_system->AddStatusFiles(Files) == false)
  1042. return false;
  1043. SPtr<DynamicMMap> Map = new DynamicMMap(0,MapSize);
  1044. unsigned long CurrentSize = 0;
  1045. unsigned long TotalSize = 0;
  1046. TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
  1047. // Build the status cache
  1048. Progress.OverallProgress(0,1,1,_("Reading package lists"));
  1049. pkgCacheGenerator Gen(Map.Get(),&Progress);
  1050. if (_error->PendingError() == true)
  1051. return false;
  1052. if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
  1053. Files.begin()+EndOfSource,Files.end()) == false)
  1054. return false;
  1055. // FIXME: move me to a better place
  1056. Gen.FinishCache(Progress);
  1057. if (_error->PendingError() == true)
  1058. return false;
  1059. *OutMap = Map.UnGuard();
  1060. return true;
  1061. }
  1062. /*}}}*/