pkgcachegen.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcachegen.cc,v 1.14 1998/08/26 04:52:23 jgg 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. #ifdef __GNUG__
  11. #pragma implementation "apt-pkg/pkgcachegen.h"
  12. #endif
  13. #include <apt-pkg/pkgcachegen.h>
  14. #include <apt-pkg/error.h>
  15. #include <apt-pkg/version.h>
  16. #include <apt-pkg/progress.h>
  17. #include <apt-pkg/sourcelist.h>
  18. #include <apt-pkg/configuration.h>
  19. #include <apt-pkg/deblistparser.h>
  20. #include <strutl.h>
  21. #include <sys/stat.h>
  22. #include <unistd.h>
  23. /*}}}*/
  24. // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
  25. // ---------------------------------------------------------------------
  26. /* We set the diry flag and make sure that is written to the disk */
  27. pkgCacheGenerator::pkgCacheGenerator(DynamicMMap &Map,OpProgress &Prog) :
  28. Map(Map), Cache(Map), Progress(Prog)
  29. {
  30. if (_error->PendingError() == true)
  31. return;
  32. if (Map.Size() == 0)
  33. {
  34. Map.RawAllocate(sizeof(pkgCache::Header));
  35. *Cache.HeaderP = pkgCache::Header();
  36. }
  37. Cache.HeaderP->Dirty = true;
  38. Map.Sync(0,sizeof(pkgCache::Header));
  39. Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
  40. }
  41. /*}}}*/
  42. // CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
  43. // ---------------------------------------------------------------------
  44. /* We sync the data then unset the dirty flag in two steps so as to
  45. advoid a problem during a crash */
  46. pkgCacheGenerator::~pkgCacheGenerator()
  47. {
  48. if (_error->PendingError() == true)
  49. return;
  50. if (Map.Sync() == false)
  51. return;
  52. Cache.HeaderP->Dirty = false;
  53. Map.Sync(0,sizeof(pkgCache::Header));
  54. }
  55. /*}}}*/
  56. // CacheGenerator::MergeList - Merge the package list /*{{{*/
  57. // ---------------------------------------------------------------------
  58. /* This provides the generation of the entries in the cache. Each loop
  59. goes through a single package record from the underlying parse engine. */
  60. bool pkgCacheGenerator::MergeList(ListParser &List)
  61. {
  62. List.Owner = this;
  63. while (List.Step() == true)
  64. {
  65. // Get a pointer to the package structure
  66. string PackageName = List.Package();
  67. pkgCache::PkgIterator Pkg;
  68. if (NewPackage(Pkg,PackageName) == false)
  69. return _error->Error("Error occured while processing %s (NewPackage)",PackageName.c_str());
  70. Progress.Progress(List.Offset());
  71. /* Get a pointer to the version structure. We know the list is sorted
  72. so we use that fact in the search. Insertion of new versions is
  73. done with correct sorting */
  74. string Version = List.Version();
  75. if (Version.empty() == true)
  76. {
  77. if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false)
  78. return _error->Error("Error occured while processing %s (UsePackage1)",PackageName.c_str());
  79. continue;
  80. }
  81. pkgCache::VerIterator Ver = Pkg.VersionList();
  82. unsigned long *Last = &Pkg->VersionList;
  83. int Res = 1;
  84. for (; Ver.end() == false; Last = &Ver->NextVer, Ver++)
  85. {
  86. Res = pkgVersionCompare(Version.begin(),Version.end(),Ver.VerStr(),
  87. Ver.VerStr() + strlen(Ver.VerStr()));
  88. if (Res >= 0)
  89. break;
  90. }
  91. /* We already have a version for this item, record that we
  92. saw it */
  93. if (Res == 0)
  94. {
  95. if (List.UsePackage(Pkg,Ver) == false)
  96. return _error->Error("Error occured while processing %s (UsePackage2)",PackageName.c_str());
  97. if (NewFileVer(Ver,List) == false)
  98. return _error->Error("Error occured while processing %s (NewFileVer1)",PackageName.c_str());
  99. continue;
  100. }
  101. // Add a new version
  102. *Last = NewVersion(Ver,Version,*Last);
  103. Ver->ParentPkg = Pkg.Index();
  104. if (List.NewVersion(Ver) == false)
  105. return _error->Error("Error occured while processing %s (NewVersion1)",PackageName.c_str());
  106. if (List.UsePackage(Pkg,Ver) == false)
  107. return _error->Error("Error occured while processing %s (UsePackage3)",PackageName.c_str());
  108. if (NewFileVer(Ver,List) == false)
  109. return _error->Error("Error occured while processing %s (NewVersion2)",PackageName.c_str());
  110. }
  111. return true;
  112. }
  113. /*}}}*/
  114. // CacheGenerator::NewPackage - Add a new package /*{{{*/
  115. // ---------------------------------------------------------------------
  116. /* This creates a new package structure and adds it to the hash table */
  117. bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,string Name)
  118. {
  119. Pkg = Cache.FindPkg(Name);
  120. if (Pkg.end() == false)
  121. return true;
  122. // Get a structure
  123. unsigned long Package = Map.Allocate(sizeof(pkgCache::Package));
  124. if (Package == 0)
  125. return false;
  126. Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package);
  127. // Insert it into the hash table
  128. unsigned long Hash = Cache.Hash(Name);
  129. Pkg->NextPackage = Cache.HeaderP->HashTable[Hash];
  130. Cache.HeaderP->HashTable[Hash] = Package;
  131. // Set the name and the ID
  132. Pkg->Name = Map.WriteString(Name);
  133. if (Pkg->Name == 0)
  134. return false;
  135. Pkg->ID = Cache.HeaderP->PackageCount++;
  136. return true;
  137. }
  138. /*}}}*/
  139. // CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
  140. // ---------------------------------------------------------------------
  141. /* */
  142. bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
  143. ListParser &List)
  144. {
  145. // Get a structure
  146. unsigned long VerFile = Map.Allocate(sizeof(pkgCache::VerFile));
  147. if (VerFile == 0)
  148. return 0;
  149. pkgCache::VerFileIterator VF(Cache,Cache.VerFileP + VerFile);
  150. VF->File = CurrentFile - Cache.PkgFileP;
  151. VF->NextFile = Ver->FileList;
  152. Ver->FileList = VF.Index();
  153. VF->Offset = List.Offset();
  154. VF->Size = List.Size();
  155. if (Cache.HeaderP->MaxVerFileSize < VF->Size)
  156. Cache.HeaderP->MaxVerFileSize = VF->Size;
  157. return true;
  158. }
  159. /*}}}*/
  160. // CacheGenerator::NewVersion - Create a new Version /*{{{*/
  161. // ---------------------------------------------------------------------
  162. /* This puts a version structure in the linked list */
  163. unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
  164. string VerStr,
  165. unsigned long Next)
  166. {
  167. // Get a structure
  168. unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
  169. if (Version == 0)
  170. return 0;
  171. // Fill it in
  172. Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
  173. Ver->NextVer = Next;
  174. Ver->ID = Cache.HeaderP->VersionCount++;
  175. Ver->VerStr = Map.WriteString(VerStr);
  176. if (Ver->VerStr == 0)
  177. return 0;
  178. return Version;
  179. }
  180. /*}}}*/
  181. // ListParser::NewDepends - Create a dependency element /*{{{*/
  182. // ---------------------------------------------------------------------
  183. /* This creates a dependency element in the tree. It is linked to the
  184. version and to the package that it is pointing to. */
  185. bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver,
  186. string PackageName,
  187. string Version,
  188. unsigned int Op,
  189. unsigned int Type)
  190. {
  191. pkgCache &Cache = Owner->Cache;
  192. // Get a structure
  193. unsigned long Dependency = Owner->Map.Allocate(sizeof(pkgCache::Dependency));
  194. if (Dependency == 0)
  195. return false;
  196. // Fill it in
  197. pkgCache::DepIterator Dep(Cache,Cache.DepP + Dependency);
  198. Dep->ParentVer = Ver.Index();
  199. Dep->Type = Type;
  200. Dep->CompareOp = Op;
  201. Dep->ID = Cache.HeaderP->DependsCount++;
  202. // Locate the target package
  203. pkgCache::PkgIterator Pkg;
  204. if (Owner->NewPackage(Pkg,PackageName) == false)
  205. return false;
  206. // Probe the reverse dependency list for a version string that matches
  207. if (Version.empty() == false)
  208. {
  209. for (pkgCache::DepIterator I = Pkg.RevDependsList(); I.end() == false; I++)
  210. if (I->Version != 0 && I.TargetVer() == Version)
  211. Dep->Version = I->Version;
  212. if (Dep->Version == 0)
  213. if ((Dep->Version = WriteString(Version)) == 0)
  214. return false;
  215. }
  216. // Link it to the package
  217. Dep->Package = Pkg.Index();
  218. Dep->NextRevDepends = Pkg->RevDepends;
  219. Pkg->RevDepends = Dep.Index();
  220. // Link it to the version (at the end of the list)
  221. unsigned long *Last = &Ver->DependsList;
  222. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  223. Last = &D->NextDepends;
  224. Dep->NextDepends = *Last;
  225. *Last = Dep.Index();
  226. return true;
  227. }
  228. /*}}}*/
  229. // ListParser::NewProvides - Create a Provides element /*{{{*/
  230. // ---------------------------------------------------------------------
  231. /* */
  232. bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver,
  233. string PackageName,
  234. string Version)
  235. {
  236. pkgCache &Cache = Owner->Cache;
  237. // We do not add self referencing provides
  238. if (Ver.ParentPkg().Name() == PackageName)
  239. return true;
  240. // Get a structure
  241. unsigned long Provides = Owner->Map.Allocate(sizeof(pkgCache::Provides));
  242. if (Provides == 0)
  243. return false;
  244. // Fill it in
  245. pkgCache::PrvIterator Prv(Cache,Cache.ProvideP + Provides,Cache.PkgP);
  246. Prv->Version = Ver.Index();
  247. Prv->NextPkgProv = Ver->ProvidesList;
  248. Ver->ProvidesList = Prv.Index();
  249. if (Version.empty() == false && (Prv->Version = WriteString(Version)) == 0)
  250. return false;
  251. // Locate the target package
  252. pkgCache::PkgIterator Pkg;
  253. if (Owner->NewPackage(Pkg,PackageName) == false)
  254. return false;
  255. // Link it to the package
  256. Prv->ParentPkg = Pkg.Index();
  257. Prv->NextProvides = Pkg->ProvidesList;
  258. Pkg->ProvidesList = Prv.Index();
  259. return true;
  260. }
  261. /*}}}*/
  262. // CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
  263. // ---------------------------------------------------------------------
  264. /* This is used to select which file is to be associated with all newly
  265. added versions. */
  266. bool pkgCacheGenerator::SelectFile(string File,unsigned long Flags)
  267. {
  268. struct stat Buf;
  269. if (stat(File.c_str(),&Buf) == -1)
  270. return _error->Errno("stat","Couldn't stat ",File.c_str());
  271. // Get some space for the structure
  272. CurrentFile = Cache.PkgFileP + Map.Allocate(sizeof(*CurrentFile));
  273. if (CurrentFile == Cache.PkgFileP)
  274. return false;
  275. // Fill it in
  276. CurrentFile->FileName = Map.WriteString(File);
  277. CurrentFile->Size = Buf.st_size;
  278. CurrentFile->mtime = Buf.st_mtime;
  279. CurrentFile->NextFile = Cache.HeaderP->FileList;
  280. CurrentFile->Flags = Flags;
  281. PkgFileName = File;
  282. Cache.HeaderP->FileList = CurrentFile - Cache.PkgFileP;
  283. Cache.HeaderP->PackageFileCount++;
  284. if (CurrentFile->FileName == 0)
  285. return false;
  286. Progress.SubProgress(Buf.st_size);
  287. return true;
  288. }
  289. /*}}}*/
  290. // CacheGenerator::WriteUniqueString - Insert a unique string /*{{{*/
  291. // ---------------------------------------------------------------------
  292. /* This is used to create handles to strings. Given the same text it
  293. always returns the same number */
  294. unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
  295. unsigned int Size)
  296. {
  297. // Search for an insertion point
  298. pkgCache::StringItem *I = Cache.StringItemP + Cache.HeaderP->StringList;
  299. int Res = 1;
  300. unsigned long *Last = &Cache.HeaderP->StringList;
  301. for (; I != Cache.StringItemP; Last = &I->NextItem,
  302. I = Cache.StringItemP + I->NextItem)
  303. {
  304. Res = stringcmp(S,S+Size,Cache.StrP + I->String);
  305. if (Res >= 0)
  306. break;
  307. }
  308. // Match
  309. if (Res == 0)
  310. return I->String;
  311. // Get a structure
  312. unsigned long Item = Map.Allocate(sizeof(pkgCache::StringItem));
  313. if (Item == 0)
  314. return 0;
  315. // Fill in the structure
  316. pkgCache::StringItem *ItemP = Cache.StringItemP + Item;
  317. ItemP->NextItem = I - Cache.StringItemP;
  318. *Last = Item;
  319. ItemP->String = Map.WriteString(S,Size);
  320. if (ItemP->String == 0)
  321. return 0;
  322. return ItemP->String;
  323. }
  324. /*}}}*/
  325. // SrcCacheCheck - Check if the source package cache is uptodate /*{{{*/
  326. // ---------------------------------------------------------------------
  327. /* The source cache is checked against the source list and the files
  328. on disk, any difference results in a false. */
  329. bool pkgSrcCacheCheck(pkgSourceList &List)
  330. {
  331. if (_error->PendingError() == true)
  332. return false;
  333. // Open the source package cache
  334. string CacheFile = _config->FindDir("Dir::Cache::srcpkgcache");
  335. string ListDir = _config->FindDir("Dir::State::lists");
  336. if (FileExists(CacheFile) == false)
  337. return false;
  338. FileFd CacheF(CacheFile,FileFd::ReadOnly);
  339. if (_error->PendingError() == true)
  340. {
  341. _error->Discard();
  342. return false;
  343. }
  344. MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
  345. if (_error->PendingError() == true)
  346. {
  347. _error->Discard();
  348. return false;
  349. }
  350. pkgCache Cache(Map);
  351. if (_error->PendingError() == true)
  352. {
  353. _error->Discard();
  354. return false;
  355. }
  356. // They are certianly out of sync
  357. if (Cache.Head().PackageFileCount != List.size())
  358. return false;
  359. for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
  360. {
  361. // Search for a match in the source list
  362. bool Bad = true;
  363. for (pkgSourceList::const_iterator I = List.begin();
  364. I != List.end(); I++)
  365. {
  366. string File = ListDir + URItoFileName(I->PackagesURI());
  367. if (F.FileName() == File)
  368. {
  369. Bad = false;
  370. break;
  371. }
  372. }
  373. // Check if the file matches what was cached
  374. Bad |= !F.IsOk();
  375. if (Bad == true)
  376. return false;
  377. }
  378. return true;
  379. }
  380. /*}}}*/
  381. // PkgCacheCheck - Check if the package cache is uptodate /*{{{*/
  382. // ---------------------------------------------------------------------
  383. /* This does a simple check of all files used to compose the cache */
  384. bool pkgPkgCacheCheck(string CacheFile)
  385. {
  386. if (_error->PendingError() == true)
  387. return false;
  388. // Open the source package cache
  389. if (FileExists(CacheFile) == false)
  390. return false;
  391. FileFd CacheF(CacheFile,FileFd::ReadOnly);
  392. if (_error->PendingError() == true)
  393. {
  394. _error->Discard();
  395. return false;
  396. }
  397. MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
  398. if (_error->PendingError() == true)
  399. {
  400. _error->Discard();
  401. return false;
  402. }
  403. pkgCache Cache(Map);
  404. if (_error->PendingError() == true)
  405. {
  406. _error->Discard();
  407. return false;
  408. }
  409. // Cheack each file
  410. for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
  411. if (F.IsOk() == false)
  412. return false;
  413. return true;
  414. }
  415. /*}}}*/
  416. // AddSourcesSize - Add the size of the status files /*{{{*/
  417. // ---------------------------------------------------------------------
  418. /* This adds the size of all the status files to the size counter */
  419. static bool pkgAddSourcesSize(unsigned long &TotalSize)
  420. {
  421. // Grab the file names
  422. string xstatus = _config->FindDir("Dir::State::xstatus");
  423. string userstatus = _config->FindDir("Dir::State::userstatus");
  424. string status = _config->FindDir("Dir::State::status");
  425. // Grab the sizes
  426. struct stat Buf;
  427. if (stat(xstatus.c_str(),&Buf) == 0)
  428. TotalSize += Buf.st_size;
  429. if (stat(userstatus.c_str(),&Buf) == 0)
  430. TotalSize += Buf.st_size;
  431. if (stat(status.c_str(),&Buf) != 0)
  432. return _error->Errno("stat","Couldn't stat the status file %s",status.c_str());
  433. TotalSize += Buf.st_size;
  434. return true;
  435. }
  436. /*}}}*/
  437. // MergeStatus - Add the status files to the cache /*{{{*/
  438. // ---------------------------------------------------------------------
  439. /* This adds the status files to the map */
  440. static bool pkgMergeStatus(OpProgress &Progress,pkgCacheGenerator &Gen,
  441. unsigned long &CurrentSize,unsigned long TotalSize)
  442. {
  443. // Grab the file names
  444. string Status[3];
  445. Status[0] = _config->FindDir("Dir::State::xstatus");
  446. Status[1]= _config->FindDir("Dir::State::userstatus");
  447. Status[2] = _config->FindDir("Dir::State::status");
  448. for (int I = 0; I != 3; I++)
  449. {
  450. // Check if the file exists and it is not the primary status file.
  451. string File = Status[I];
  452. if (I != 2 && FileExists(File) == false)
  453. continue;
  454. FileFd Pkg(File,FileFd::ReadOnly);
  455. debListParser Parser(Pkg);
  456. Progress.OverallProgress(CurrentSize,TotalSize,Pkg.Size(),"Reading Package Lists");
  457. if (_error->PendingError() == true)
  458. return _error->Error("Problem opening %s",File.c_str());
  459. CurrentSize += Pkg.Size();
  460. Progress.SubProgress(0,"Local Package State - " + flNotDir(File));
  461. if (Gen.SelectFile(File,pkgCache::Flag::NotSource) == false)
  462. return _error->Error("Problem with SelectFile %s",File.c_str());
  463. if (Gen.MergeList(Parser) == false)
  464. return _error->Error("Problem with MergeList %s",File.c_str());
  465. Progress.Progress(Pkg.Size());
  466. }
  467. return true;
  468. }
  469. /*}}}*/
  470. // MakeStatusCache - Generates a cache that includes the status files /*{{{*/
  471. // ---------------------------------------------------------------------
  472. /* This copies the package source cache and then merges the status and
  473. xstatus files into it. */
  474. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress)
  475. {
  476. Progress.OverallProgress(0,1,1,"Reading Package Lists");
  477. string CacheFile = _config->FindDir("Dir::Cache::pkgcache");
  478. bool SrcOk = pkgSrcCacheCheck(List);
  479. bool PkgOk = pkgPkgCacheCheck(CacheFile);
  480. // Rebuild the source and package caches
  481. if (SrcOk == false)
  482. {
  483. string SCacheFile = _config->FindDir("Dir::Cache::srcpkgcache");
  484. string ListDir = _config->FindDir("Dir::State::lists");
  485. FileFd SCacheF(SCacheFile,FileFd::WriteEmpty);
  486. FileFd CacheF(CacheFile,FileFd::WriteEmpty);
  487. DynamicMMap Map(CacheF,MMap::Public);
  488. if (_error->PendingError() == true)
  489. return false;
  490. pkgCacheGenerator Gen(Map,Progress);
  491. // Prepare the progress indicator
  492. unsigned long TotalSize = 0;
  493. struct stat Buf;
  494. for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
  495. {
  496. string File = ListDir + URItoFileName(I->PackagesURI());
  497. if (stat(File.c_str(),&Buf) != 0)
  498. return _error->Errno("stat","Couldn't stat source package list %s",File.c_str());
  499. TotalSize += Buf.st_size;
  500. }
  501. if (pkgAddSourcesSize(TotalSize) == false)
  502. return false;
  503. // Generate the pkg source cache
  504. unsigned long CurrentSize = 0;
  505. for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
  506. {
  507. string File = ListDir + URItoFileName(I->PackagesURI());
  508. FileFd Pkg(File,FileFd::ReadOnly);
  509. debListParser Parser(Pkg);
  510. Progress.OverallProgress(CurrentSize,TotalSize,Pkg.Size(),"Reading Package Lists");
  511. if (_error->PendingError() == true)
  512. return _error->Error("Problem opening %s",File.c_str());
  513. CurrentSize += Pkg.Size();
  514. Progress.SubProgress(0,I->PackagesInfo());
  515. if (Gen.SelectFile(File) == false)
  516. return _error->Error("Problem with SelectFile %s",File.c_str());
  517. if (Gen.MergeList(Parser) == false)
  518. return _error->Error("Problem with MergeList %s",File.c_str());
  519. }
  520. // Write the src cache
  521. Gen.GetCache().HeaderP->Dirty = false;
  522. if (SCacheF.Write(Map.Data(),Map.Size()) == false)
  523. return _error->Error("IO Error saving source cache");
  524. Gen.GetCache().HeaderP->Dirty = true;
  525. // Merge in the source caches
  526. return pkgMergeStatus(Progress,Gen,CurrentSize,TotalSize);
  527. }
  528. if (PkgOk == true)
  529. {
  530. Progress.OverallProgress(1,1,1,"Reading Package Lists");
  531. return true;
  532. }
  533. // We use the source cache to generate the package cache
  534. string SCacheFile = _config->FindDir("Dir::Cache::srcpkgcache");
  535. FileFd SCacheF(SCacheFile,FileFd::ReadOnly);
  536. FileFd CacheF(CacheFile,FileFd::WriteEmpty);
  537. DynamicMMap Map(CacheF,MMap::Public);
  538. if (_error->PendingError() == true)
  539. return false;
  540. // Preload the map with the source cache
  541. if (SCacheF.Read((unsigned char *)Map.Data() + Map.RawAllocate(SCacheF.Size()),
  542. SCacheF.Size()) == false)
  543. return false;
  544. pkgCacheGenerator Gen(Map,Progress);
  545. // Compute the progress
  546. unsigned long TotalSize = 0;
  547. if (pkgAddSourcesSize(TotalSize) == false)
  548. return false;
  549. unsigned long CurrentSize = 0;
  550. return pkgMergeStatus(Progress,Gen,CurrentSize,TotalSize);
  551. }
  552. /*}}}*/