]>
git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcachegen.cc,v 1.37 1999/04/19 02:35:38 jgg Exp $
4 /* ######################################################################
6 Package Cache Generator - Generator for the cache structure.
8 This builds the cache structure from the abstract package list parser.
10 ##################################################################### */
12 // Include Files /*{{{*/
14 #pragma implementation "apt-pkg/pkgcachegen.h"
17 #include <apt-pkg/pkgcachegen.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/version.h>
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 #include <apt-pkg/strutl.h>
32 // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
33 // ---------------------------------------------------------------------
34 /* We set the diry flag and make sure that is written to the disk */
35 pkgCacheGenerator::pkgCacheGenerator(DynamicMMap
&Map
,OpProgress
&Prog
) :
36 Map(Map
), Cache(Map
), Progress(Prog
)
38 if (_error
->PendingError() == true)
43 Map
.RawAllocate(sizeof(pkgCache::Header
));
44 *Cache
.HeaderP
= pkgCache::Header();
46 Cache
.HeaderP
->Dirty
= true;
47 Map
.Sync(0,sizeof(pkgCache::Header
));
48 Map
.UsePools(*Cache
.HeaderP
->Pools
,sizeof(Cache
.HeaderP
->Pools
)/sizeof(Cache
.HeaderP
->Pools
[0]));
49 memset(UniqHash
,0,sizeof(UniqHash
));
52 // CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
53 // ---------------------------------------------------------------------
54 /* We sync the data then unset the dirty flag in two steps so as to
55 advoid a problem during a crash */
56 pkgCacheGenerator::~pkgCacheGenerator()
58 if (_error
->PendingError() == true)
60 if (Map
.Sync() == false)
63 Cache
.HeaderP
->Dirty
= false;
64 Map
.Sync(0,sizeof(pkgCache::Header
));
67 // CacheGenerator::MergeList - Merge the package list /*{{{*/
68 // ---------------------------------------------------------------------
69 /* This provides the generation of the entries in the cache. Each loop
70 goes through a single package record from the underlying parse engine. */
71 bool pkgCacheGenerator::MergeList(ListParser
&List
)
75 unsigned int Counter
= 0;
76 while (List
.Step() == true)
78 // Get a pointer to the package structure
79 string PackageName
= List
.Package();
80 if (PackageName
.empty() == true)
83 pkgCache::PkgIterator Pkg
;
84 if (NewPackage(Pkg
,PackageName
) == false)
85 return _error
->Error("Error occured while processing %s (NewPackage)",PackageName
.c_str());
87 if (Counter
% 100 == 0)
88 Progress
.Progress(List
.Offset());
90 /* Get a pointer to the version structure. We know the list is sorted
91 so we use that fact in the search. Insertion of new versions is
92 done with correct sorting */
93 string Version
= List
.Version();
94 if (Version
.empty() == true)
96 if (List
.UsePackage(Pkg
,pkgCache::VerIterator(Cache
)) == false)
97 return _error
->Error("Error occured while processing %s (UsePackage1)",PackageName
.c_str());
101 pkgCache::VerIterator Ver
= Pkg
.VersionList();
102 __apt_ptrloc
*Last
= &Pkg
->VersionList
;
104 for (; Ver
.end() == false; Last
= &Ver
->NextVer
, Ver
++)
106 Res
= pkgVersionCompare(Version
.begin(),Version
.end(),Ver
.VerStr(),
107 Ver
.VerStr() + strlen(Ver
.VerStr()));
112 /* We already have a version for this item, record that we
116 if (List
.UsePackage(Pkg
,Ver
) == false)
117 return _error
->Error("Error occured while processing %s (UsePackage2)",PackageName
.c_str());
119 if (NewFileVer(Ver
,List
) == false)
120 return _error
->Error("Error occured while processing %s (NewFileVer1)",PackageName
.c_str());
126 *Last
= NewVersion(Ver
,Version
,*Last
);
127 Ver
->ParentPkg
= Pkg
.Index();
128 if (List
.NewVersion(Ver
) == false)
129 return _error
->Error("Error occured while processing %s (NewVersion1)",PackageName
.c_str());
131 if (List
.UsePackage(Pkg
,Ver
) == false)
132 return _error
->Error("Error occured while processing %s (UsePackage3)",PackageName
.c_str());
134 if (NewFileVer(Ver
,List
) == false)
135 return _error
->Error("Error occured while processing %s (NewVersion2)",PackageName
.c_str());
141 // CacheGenerator::NewPackage - Add a new package /*{{{*/
142 // ---------------------------------------------------------------------
143 /* This creates a new package structure and adds it to the hash table */
144 bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator
&Pkg
,string Name
)
146 Pkg
= Cache
.FindPkg(Name
);
147 if (Pkg
.end() == false)
151 unsigned long Package
= Map
.Allocate(sizeof(pkgCache::Package
));
155 Pkg
= pkgCache::PkgIterator(Cache
,Cache
.PkgP
+ Package
);
157 // Insert it into the hash table
158 unsigned long Hash
= Cache
.Hash(Name
);
159 Pkg
->NextPackage
= Cache
.HeaderP
->HashTable
[Hash
];
160 Cache
.HeaderP
->HashTable
[Hash
] = Package
;
162 // Set the name and the ID
163 Pkg
->Name
= Map
.WriteString(Name
);
166 Pkg
->ID
= Cache
.HeaderP
->PackageCount
++;
171 // CacheGenerator::NewFileVer - Create a new File<->Version association /*{{{*/
172 // ---------------------------------------------------------------------
174 bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator
&Ver
,
178 unsigned long VerFile
= Map
.Allocate(sizeof(pkgCache::VerFile
));
182 pkgCache::VerFileIterator
VF(Cache
,Cache
.VerFileP
+ VerFile
);
183 VF
->File
= CurrentFile
- Cache
.PkgFileP
;
185 // Link it to the end of the list
186 __apt_ptrloc
*Last
= &Ver
->FileList
;
187 for (pkgCache::VerFileIterator V
= Ver
.FileList(); V
.end() == false; V
++)
189 VF
->NextFile
= *Last
;
192 VF
->Offset
= List
.Offset();
193 VF
->Size
= List
.Size();
194 if (Cache
.HeaderP
->MaxVerFileSize
< VF
->Size
)
195 Cache
.HeaderP
->MaxVerFileSize
= VF
->Size
;
196 Cache
.HeaderP
->VerFileCount
++;
201 // CacheGenerator::NewVersion - Create a new Version /*{{{*/
202 // ---------------------------------------------------------------------
203 /* This puts a version structure in the linked list */
204 unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator
&Ver
,
209 unsigned long Version
= Map
.Allocate(sizeof(pkgCache::Version
));
214 Ver
= pkgCache::VerIterator(Cache
,Cache
.VerP
+ Version
);
216 Ver
->ID
= Cache
.HeaderP
->VersionCount
++;
217 Ver
->VerStr
= Map
.WriteString(VerStr
);
218 if (Ver
->VerStr
== 0)
224 // ListParser::NewDepends - Create a dependency element /*{{{*/
225 // ---------------------------------------------------------------------
226 /* This creates a dependency element in the tree. It is linked to the
227 version and to the package that it is pointing to. */
228 bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver
,
234 pkgCache
&Cache
= Owner
->Cache
;
237 unsigned long Dependency
= Owner
->Map
.Allocate(sizeof(pkgCache::Dependency
));
242 pkgCache::DepIterator
Dep(Cache
,Cache
.DepP
+ Dependency
);
243 Dep
->ParentVer
= Ver
.Index();
246 Dep
->ID
= Cache
.HeaderP
->DependsCount
++;
248 // Locate the target package
249 pkgCache::PkgIterator Pkg
;
250 if (Owner
->NewPackage(Pkg
,PackageName
) == false)
253 // Probe the reverse dependency list for a version string that matches
254 if (Version
.empty() == false)
256 /* for (pkgCache::DepIterator I = Pkg.RevDependsList(); I.end() == false; I++, Hit++)
257 if (I->Version != 0 && I.TargetVer() == Version)
258 Dep->Version = I->Version;*/
259 if (Dep
->Version
== 0)
260 if ((Dep
->Version
= WriteString(Version
)) == 0)
264 // Link it to the package
265 Dep
->Package
= Pkg
.Index();
266 Dep
->NextRevDepends
= Pkg
->RevDepends
;
267 Pkg
->RevDepends
= Dep
.Index();
269 /* Link it to the version (at the end of the list)
270 Caching the old end point speeds up generation substantially */
271 if (OldDepVer
!= Ver
)
273 OldDepLast
= &Ver
->DependsList
;
274 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false; D
++)
275 OldDepLast
= &D
->NextDepends
;
279 Dep
->NextDepends
= *OldDepLast
;
280 *OldDepLast
= Dep
.Index();
281 OldDepLast
= &Dep
->NextDepends
;
286 // ListParser::NewProvides - Create a Provides element /*{{{*/
287 // ---------------------------------------------------------------------
289 bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver
,
293 pkgCache
&Cache
= Owner
->Cache
;
295 // We do not add self referencing provides
296 if (Ver
.ParentPkg().Name() == PackageName
)
300 unsigned long Provides
= Owner
->Map
.Allocate(sizeof(pkgCache::Provides
));
303 Cache
.HeaderP
->ProvidesCount
++;
306 pkgCache::PrvIterator
Prv(Cache
,Cache
.ProvideP
+ Provides
,Cache
.PkgP
);
307 Prv
->Version
= Ver
.Index();
308 Prv
->NextPkgProv
= Ver
->ProvidesList
;
309 Ver
->ProvidesList
= Prv
.Index();
310 if (Version
.empty() == false && (Prv
->Version
= WriteString(Version
)) == 0)
313 // Locate the target package
314 pkgCache::PkgIterator Pkg
;
315 if (Owner
->NewPackage(Pkg
,PackageName
) == false)
318 // Link it to the package
319 Prv
->ParentPkg
= Pkg
.Index();
320 Prv
->NextProvides
= Pkg
->ProvidesList
;
321 Pkg
->ProvidesList
= Prv
.Index();
326 // CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
327 // ---------------------------------------------------------------------
328 /* This is used to select which file is to be associated with all newly
330 bool pkgCacheGenerator::SelectFile(string File
,unsigned long Flags
)
333 if (stat(File
.c_str(),&Buf
) == -1)
334 return _error
->Errno("stat","Couldn't stat ",File
.c_str());
336 // Get some space for the structure
337 CurrentFile
= Cache
.PkgFileP
+ Map
.Allocate(sizeof(*CurrentFile
));
338 if (CurrentFile
== Cache
.PkgFileP
)
342 CurrentFile
->FileName
= Map
.WriteString(File
);
343 CurrentFile
->Size
= Buf
.st_size
;
344 CurrentFile
->mtime
= Buf
.st_mtime
;
345 CurrentFile
->NextFile
= Cache
.HeaderP
->FileList
;
346 CurrentFile
->Flags
= Flags
;
347 CurrentFile
->ID
= Cache
.HeaderP
->PackageFileCount
;
349 Cache
.HeaderP
->FileList
= CurrentFile
- Cache
.PkgFileP
;
350 Cache
.HeaderP
->PackageFileCount
++;
352 if (CurrentFile
->FileName
== 0)
355 Progress
.SubProgress(Buf
.st_size
);
359 // CacheGenerator::WriteUniqueString - Insert a unique string /*{{{*/
360 // ---------------------------------------------------------------------
361 /* This is used to create handles to strings. Given the same text it
362 always returns the same number */
363 unsigned long pkgCacheGenerator::WriteUniqString(const char *S
,
366 /* We use a very small transient hash table here, this speeds up generation
367 by a fair amount on slower machines */
368 pkgCache::StringItem
*&Bucket
= UniqHash
[(S
[0]*5 + S
[1]) % _count(UniqHash
)];
370 stringcmp(S
,S
+Size
,Cache
.StrP
+ Bucket
->String
) == 0)
371 return Bucket
->String
;
373 // Search for an insertion point
374 pkgCache::StringItem
*I
= Cache
.StringItemP
+ Cache
.HeaderP
->StringList
;
376 __apt_ptrloc
*Last
= &Cache
.HeaderP
->StringList
;
377 for (; I
!= Cache
.StringItemP
; Last
= &I
->NextItem
,
378 I
= Cache
.StringItemP
+ I
->NextItem
)
380 Res
= stringcmp(S
,S
+Size
,Cache
.StrP
+ I
->String
);
393 unsigned long Item
= Map
.Allocate(sizeof(pkgCache::StringItem
));
397 // Fill in the structure
398 pkgCache::StringItem
*ItemP
= Cache
.StringItemP
+ Item
;
399 ItemP
->NextItem
= I
- Cache
.StringItemP
;
401 ItemP
->String
= Map
.WriteString(S
,Size
);
402 if (ItemP
->String
== 0)
406 return ItemP
->String
;
410 // SrcCacheCheck - Check if the source package cache is uptodate /*{{{*/
411 // ---------------------------------------------------------------------
412 /* The source cache is checked against the source list and the files
413 on disk, any difference results in a false. */
414 bool pkgSrcCacheCheck(pkgSourceList
&List
)
416 if (_error
->PendingError() == true)
419 string CacheFile
= _config
->FindFile("Dir::Cache::srcpkgcache");
420 string ListDir
= _config
->FindDir("Dir::State::lists");
422 // Count the number of missing files
424 for (pkgSourceList::const_iterator I
= List
.begin(); I
!= List
.end(); I
++)
426 // Only cache deb source types.
427 if (I
->Type
!= pkgSourceList::Item::Deb
)
433 string File
= ListDir
+ URItoFileName(I
->PackagesURI());
435 if (stat(File
.c_str(),&Buf
) != 0)
437 _error
->WarningE("stat","Couldn't stat source package list '%s' (%s)",
438 I
->PackagesInfo().c_str(),File
.c_str());
443 // Open the source package cache
444 if (FileExists(CacheFile
) == false)
447 FileFd
CacheF(CacheFile
,FileFd::ReadOnly
);
448 if (_error
->PendingError() == true)
454 MMap
Map(CacheF
,MMap::Public
| MMap::ReadOnly
);
455 if (_error
->PendingError() == true || Map
.Size() == 0)
462 if (_error
->PendingError() == true)
468 // They are certianly out of sync
469 if (Cache
.Head().PackageFileCount
!= List
.size() - Missing
)
472 for (pkgCache::PkgFileIterator
F(Cache
); F
.end() == false; F
++)
474 // Search for a match in the source list
476 for (pkgSourceList::const_iterator I
= List
.begin();
477 I
!= List
.end(); I
++)
479 // Only cache deb source types.
480 if (I
->Type
!= pkgSourceList::Item::Deb
)
483 string File
= ListDir
+ URItoFileName(I
->PackagesURI());
484 if (F
.FileName() == File
)
491 // Check if the file matches what was cached
500 // PkgCacheCheck - Check if the package cache is uptodate /*{{{*/
501 // ---------------------------------------------------------------------
502 /* This does a simple check of all files used to compose the cache */
503 bool pkgPkgCacheCheck(string CacheFile
)
505 if (_error
->PendingError() == true)
508 // Open the source package cache
509 if (FileExists(CacheFile
) == false)
512 FileFd
CacheF(CacheFile
,FileFd::ReadOnly
);
513 if (_error
->PendingError() == true)
519 MMap
Map(CacheF
,MMap::Public
| MMap::ReadOnly
);
520 if (_error
->PendingError() == true || Map
.Size() == 0)
527 if (_error
->PendingError() == true)
533 // Status files that must be in the cache
535 Status
[0] = _config
->FindFile("Dir::State::xstatus");
536 Status
[1]= _config
->FindFile("Dir::State::userstatus");
537 Status
[2] = _config
->FindFile("Dir::State::status");
540 for (pkgCache::PkgFileIterator
F(Cache
); F
.end() == false; F
++)
542 if (F
.IsOk() == false)
545 // See if this is one of the status files
546 for (int I
= 0; I
!= 3; I
++)
547 if (F
.FileName() == Status
[I
])
548 Status
[I
] = string();
551 // Make sure all the status files are loaded.
552 for (int I
= 0; I
!= 3; I
++)
554 if (Status
[I
].empty() == false && FileExists(Status
[I
]) == true)
561 // AddSourcesSize - Add the size of the status files /*{{{*/
562 // ---------------------------------------------------------------------
563 /* This adds the size of all the status files to the size counter */
564 static bool pkgAddSourcesSize(unsigned long &TotalSize
)
566 // Grab the file names
567 string xstatus
= _config
->FindFile("Dir::State::xstatus");
568 string userstatus
= _config
->FindFile("Dir::State::userstatus");
569 string status
= _config
->FindFile("Dir::State::status");
573 if (stat(xstatus
.c_str(),&Buf
) == 0)
574 TotalSize
+= Buf
.st_size
;
575 if (stat(userstatus
.c_str(),&Buf
) == 0)
576 TotalSize
+= Buf
.st_size
;
577 if (stat(status
.c_str(),&Buf
) != 0)
578 return _error
->Errno("stat","Couldn't stat the status file %s",status
.c_str());
579 TotalSize
+= Buf
.st_size
;
584 // MergeStatus - Add the status files to the cache /*{{{*/
585 // ---------------------------------------------------------------------
586 /* This adds the status files to the map */
587 static bool pkgMergeStatus(OpProgress
&Progress
,pkgCacheGenerator
&Gen
,
588 unsigned long &CurrentSize
,unsigned long TotalSize
)
590 // Grab the file names
592 Status
[0] = _config
->FindFile("Dir::State::xstatus");
593 Status
[1]= _config
->FindFile("Dir::State::userstatus");
594 Status
[2] = _config
->FindFile("Dir::State::status");
596 for (int I
= 0; I
!= 3; I
++)
598 // Check if the file exists and it is not the primary status file.
599 string File
= Status
[I
];
600 if (I
!= 2 && FileExists(File
) == false)
603 FileFd
Pkg(File
,FileFd::ReadOnly
);
604 debListParser
Parser(Pkg
);
605 Progress
.OverallProgress(CurrentSize
,TotalSize
,Pkg
.Size(),"Reading Package Lists");
606 if (_error
->PendingError() == true)
607 return _error
->Error("Problem opening %s",File
.c_str());
608 CurrentSize
+= Pkg
.Size();
610 Progress
.SubProgress(0,"Local Package State - " + flNotDir(File
));
611 if (Gen
.SelectFile(File
,pkgCache::Flag::NotSource
) == false)
612 return _error
->Error("Problem with SelectFile %s",File
.c_str());
614 if (Gen
.MergeList(Parser
) == false)
615 return _error
->Error("Problem with MergeList %s",File
.c_str());
616 Progress
.Progress(Pkg
.Size());
622 // GenerateSrcCache - Write the source package lists to the map /*{{{*/
623 // ---------------------------------------------------------------------
624 /* This puts the source package cache into the given generator. */
625 bool pkgGenerateSrcCache(pkgSourceList
&List
,OpProgress
&Progress
,
626 pkgCacheGenerator
&Gen
,
627 unsigned long &CurrentSize
,unsigned long &TotalSize
)
629 string ListDir
= _config
->FindDir("Dir::State::lists");
631 // Prepare the progress indicator
634 for (pkgSourceList::const_iterator I
= List
.begin(); I
!= List
.end(); I
++)
636 string File
= ListDir
+ URItoFileName(I
->PackagesURI());
637 if (stat(File
.c_str(),&Buf
) != 0)
639 TotalSize
+= Buf
.st_size
;
642 if (pkgAddSourcesSize(TotalSize
) == false)
645 // Generate the pkg source cache
647 for (pkgSourceList::const_iterator I
= List
.begin(); I
!= List
.end(); I
++)
649 // Only cache deb source types.
650 if (I
->Type
!= pkgSourceList::Item::Deb
)
653 string File
= ListDir
+ URItoFileName(I
->PackagesURI());
655 if (FileExists(File
) == false)
658 FileFd
Pkg(File
,FileFd::ReadOnly
);
659 debListParser
Parser(Pkg
);
660 Progress
.OverallProgress(CurrentSize
,TotalSize
,Pkg
.Size(),"Reading Package Lists");
661 if (_error
->PendingError() == true)
662 return _error
->Error("Problem opening %s",File
.c_str());
663 CurrentSize
+= Pkg
.Size();
665 Progress
.SubProgress(0,I
->PackagesInfo());
666 if (Gen
.SelectFile(File
) == false)
667 return _error
->Error("Problem with SelectFile %s",File
.c_str());
669 if (Gen
.MergeList(Parser
) == false)
670 return _error
->Error("Problem with MergeList %s",File
.c_str());
672 // Check the release file
673 string RFile
= ListDir
+ URItoFileName(I
->ReleaseURI());
674 if (FileExists(RFile
) == true)
676 FileFd
Rel(RFile
,FileFd::ReadOnly
);
677 if (_error
->PendingError() == true)
679 Parser
.LoadReleaseInfo(Gen
.GetCurFile(),Rel
);
686 // MakeStatusCache - Generates a cache that includes the status files /*{{{*/
687 // ---------------------------------------------------------------------
688 /* This copies the package source cache and then merges the status and
689 xstatus files into it. */
690 bool pkgMakeStatusCache(pkgSourceList
&List
,OpProgress
&Progress
)
692 Progress
.OverallProgress(0,1,1,"Reading Package Lists");
694 string CacheFile
= _config
->FindFile("Dir::Cache::pkgcache");
695 bool SrcOk
= pkgSrcCacheCheck(List
);
696 bool PkgOk
= SrcOk
&& pkgPkgCacheCheck(CacheFile
);
698 // Rebuild the source and package caches
701 string SCacheFile
= _config
->FindFile("Dir::Cache::srcpkgcache");
702 FileFd
SCacheF(SCacheFile
,FileFd::WriteEmpty
);
703 FileFd
CacheF(CacheFile
,FileFd::WriteEmpty
);
704 DynamicMMap
Map(CacheF
,MMap::Public
);
705 if (_error
->PendingError() == true)
708 pkgCacheGenerator
Gen(Map
,Progress
);
709 unsigned long CurrentSize
= 0;
710 unsigned long TotalSize
= 0;
711 if (pkgGenerateSrcCache(List
,Progress
,Gen
,CurrentSize
,TotalSize
) == false)
714 // Write the src cache
715 Gen
.GetCache().HeaderP
->Dirty
= false;
716 if (SCacheF
.Write(Map
.Data(),Map
.Size()) == false)
717 return _error
->Error("IO Error saving source cache");
718 Gen
.GetCache().HeaderP
->Dirty
= true;
720 // Merge in the source caches
721 return pkgMergeStatus(Progress
,Gen
,CurrentSize
,TotalSize
);
726 Progress
.OverallProgress(1,1,1,"Reading Package Lists");
730 // We use the source cache to generate the package cache
731 string SCacheFile
= _config
->FindFile("Dir::Cache::srcpkgcache");
733 FileFd
SCacheF(SCacheFile
,FileFd::ReadOnly
);
734 FileFd
CacheF(CacheFile
,FileFd::WriteEmpty
);
735 DynamicMMap
Map(CacheF
,MMap::Public
);
736 if (_error
->PendingError() == true)
739 // Preload the map with the source cache
740 if (SCacheF
.Read((unsigned char *)Map
.Data() + Map
.RawAllocate(SCacheF
.Size()),
741 SCacheF
.Size()) == false)
744 pkgCacheGenerator
Gen(Map
,Progress
);
746 // Compute the progress
747 unsigned long TotalSize
= 0;
748 if (pkgAddSourcesSize(TotalSize
) == false)
751 unsigned long CurrentSize
= 0;
752 return pkgMergeStatus(Progress
,Gen
,CurrentSize
,TotalSize
);
755 // MakeStatusCacheMem - Returns a map for the status cache /*{{{*/
756 // ---------------------------------------------------------------------
757 /* This creates a map object for the status cache. If the process has write
758 access to the caches then it is the same as MakeStatusCache, otherwise it
759 creates a memory block and puts the cache in there. */
760 MMap
*pkgMakeStatusCacheMem(pkgSourceList
&List
,OpProgress
&Progress
)
762 /* If the cache file is writeable this is just a wrapper for
764 string CacheFile
= _config
->FindFile("Dir::Cache::pkgcache");
765 bool Writeable
= (access(CacheFile
.c_str(),W_OK
) == 0) ||
768 if (Writeable
== true)
770 if (pkgMakeStatusCache(List
,Progress
) == false)
773 // Open the cache file
774 FileFd
File(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
775 if (_error
->PendingError() == true)
778 MMap
*Map
= new MMap(File
,MMap::Public
| MMap::ReadOnly
);
779 if (_error
->PendingError() == true)
787 // Mostly from MakeStatusCache..
788 Progress
.OverallProgress(0,1,1,"Reading Package Lists");
790 bool SrcOk
= pkgSrcCacheCheck(List
);
791 bool PkgOk
= SrcOk
&& pkgPkgCacheCheck(CacheFile
);
793 // Rebuild the source and package caches
796 DynamicMMap
*Map
= new DynamicMMap(MMap::Public
);
797 if (_error
->PendingError() == true)
803 pkgCacheGenerator
Gen(*Map
,Progress
);
804 unsigned long CurrentSize
= 0;
805 unsigned long TotalSize
= 0;
806 if (pkgGenerateSrcCache(List
,Progress
,Gen
,CurrentSize
,TotalSize
) == false)
812 // Merge in the source caches
813 if (pkgMergeStatus(Progress
,Gen
,CurrentSize
,TotalSize
) == false)
824 Progress
.OverallProgress(1,1,1,"Reading Package Lists");
826 // Open the cache file
827 FileFd
File(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
828 if (_error
->PendingError() == true)
831 MMap
*Map
= new MMap(File
,MMap::Public
| MMap::ReadOnly
);
832 if (_error
->PendingError() == true)
840 // We use the source cache to generate the package cache
841 string SCacheFile
= _config
->FindFile("Dir::Cache::srcpkgcache");
842 FileFd
SCacheF(SCacheFile
,FileFd::ReadOnly
);
843 DynamicMMap
*Map
= new DynamicMMap(MMap::Public
);
844 if (_error
->PendingError() == true)
850 // Preload the map with the source cache
851 if (SCacheF
.Read((unsigned char *)Map
->Data() + Map
->RawAllocate(SCacheF
.Size()),
852 SCacheF
.Size()) == false)
858 pkgCacheGenerator
Gen(*Map
,Progress
);
860 // Compute the progress
861 unsigned long TotalSize
= 0;
862 if (pkgAddSourcesSize(TotalSize
) == false)
868 unsigned long CurrentSize
= 0;
869 if (pkgMergeStatus(Progress
,Gen
,CurrentSize
,TotalSize
) == false)