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