Browse Source

* apt-pkg/cachefile.{cc,h}:

- split Open() into submethods to be able to build only parts
  - make the OpProgress optional in the Cache buildprocess
tags/debian/0.8.0
David Kalnischkies 11 years ago
parent
commit
2e5f4e45f5
8 changed files with 103 additions and 52 deletions
  1. +36
    -14
      apt-pkg/cachefile.cc
  2. +9
    -6
      apt-pkg/cachefile.h
  3. +10
    -8
      apt-pkg/deb/debindexfile.cc
  4. +3
    -3
      apt-pkg/deb/debindexfile.h
  5. +6
    -2
      apt-pkg/indexfile.h
  6. +28
    -17
      apt-pkg/pkgcachegen.cc
  7. +8
    -2
      apt-pkg/pkgcachegen.h
  8. +3
    -0
      debian/changelog

+ 36
- 14
apt-pkg/cachefile.cc View File

@@ -46,7 +46,7 @@ pkgCacheFile::~pkgCacheFile()
// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
{
const bool ErrorWasEmpty = _error->empty();
if (WithLock == true)
@@ -65,8 +65,9 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
return _error->Error(_("The list of sources could not be read."));

// Read the caches
bool Res = pkgMakeStatusCache(List,Progress,&Map,!WithLock);
Progress.Done();
bool Res = pkgCacheGenerator::MakeStatusCache(List,Progress,&Map,!WithLock);
if (Progress != NULL)
Progress->Done();
if (Res == false)
return _error->Error(_("The package lists or status file could not be parsed or opened."));

@@ -80,29 +81,50 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
return true;
}
/*}}}*/
// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
// CacheFile::BuildPolicy - Open and build all relevant preferences /*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
bool pkgCacheFile::BuildPolicy(OpProgress *Progress)
{
if (BuildCaches(Progress,WithLock) == false)
return false;
// The policy engine
Policy = new pkgPolicy(Cache);
if (_error->PendingError() == true)
return false;

if (ReadPinFile(*Policy) == false || ReadPinDir(*Policy) == false)
return false;
// Create the dependency cache

return true;
}
/*}}}*/
// CacheFile::BuildDepCache - Open and build the dependency cache /*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgCacheFile::BuildDepCache(OpProgress *Progress)
{
DCache = new pkgDepCache(Cache,Policy);
if (_error->PendingError() == true)
return false;
DCache->Init(&Progress);
Progress.Done();

DCache->Init(Progress);
return true;
}
/*}}}*/
// CacheFile::Open - Open the cache files, creating if necessary /*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgCacheFile::Open(OpProgress *Progress, bool WithLock)
{
if (BuildCaches(Progress,WithLock) == false)
return false;

if (BuildPolicy(Progress) == false)
return false;

if (BuildDepCache(Progress) == false)
return false;

if (Progress != NULL)
Progress->Done();
if (_error->PendingError() == true)
return false;


+ 9
- 6
apt-pkg/cachefile.h View File

@@ -30,11 +30,10 @@ class pkgCacheFile
MMap *Map;
pkgCache *Cache;
pkgDepCache *DCache;
pkgPolicy *Policy;

public:

pkgPolicy *Policy;
// We look pretty much exactly like a pointer to a dep cache
inline operator pkgCache &() {return *Cache;};
inline operator pkgCache *() {return Cache;};
@@ -45,12 +44,16 @@ class pkgCacheFile
inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};

bool BuildCaches(OpProgress &Progress,bool WithLock = true);
bool Open(OpProgress &Progress,bool WithLock = true);
bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
__deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
bool BuildPolicy(OpProgress *Progress = NULL);
bool BuildDepCache(OpProgress *Progress = NULL);
bool Open(OpProgress *Progress = NULL, bool WithLock = true);
__deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
void Close();
pkgCacheFile();
~pkgCacheFile();
virtual ~pkgCacheFile();
};

#endif

+ 10
- 8
apt-pkg/deb/debindexfile.cc View File

@@ -262,15 +262,15 @@ unsigned long debPackagesIndex::Size() const
// PackagesIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
string PackageFile = IndexFile("Packages");
FileFd Pkg(PackageFile,FileFd::ReadOnly);
debListParser Parser(&Pkg, Architecture);
if (_error->PendingError() == true)
return _error->Error("Problem opening %s",PackageFile.c_str());
Prog.SubProgress(0,Info("Packages"));
if (Prog != NULL)
Prog->SubProgress(0,Info("Packages"));
::URI Tmp(URI);
if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false)
return _error->Error("Problem with SelectFile %s",PackageFile.c_str());
@@ -445,7 +445,7 @@ unsigned long debTranslationsIndex::Size() const
// TranslationsIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
// Check the translation file, if in use
string TranslationFile = IndexFile(Language);
@@ -456,7 +456,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
if (_error->PendingError() == true)
return false;
Prog.SubProgress(0, Info(TranslationFile.c_str()));
if (Prog != NULL)
Prog->SubProgress(0, Info(TranslationFile.c_str()));
if (Gen.SelectFile(TranslationFile,string(),*this) == false)
return _error->Error("Problem with SelectFile %s",TranslationFile.c_str());

@@ -529,7 +530,7 @@ unsigned long debStatusIndex::Size() const
// StatusIndex::Merge - Load the index file into a cache /*{{{*/
// ---------------------------------------------------------------------
/* */
bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
FileFd Pkg(File,FileFd::ReadOnly);
if (_error->PendingError() == true)
@@ -537,8 +538,9 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const
debListParser Parser(&Pkg);
if (_error->PendingError() == true)
return false;
Prog.SubProgress(0,File);

if (Prog != NULL)
Prog->SubProgress(0,File);
if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false)
return _error->Error("Problem with SelectFile %s",File.c_str());



+ 3
- 3
apt-pkg/deb/debindexfile.h View File

@@ -35,7 +35,7 @@ class debStatusIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

debStatusIndex(string File);
@@ -67,7 +67,7 @@ class debPackagesIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const {return true;};
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

debPackagesIndex(string const &URI, string const &Dist, string const &Section,
@@ -99,7 +99,7 @@ class debTranslationsIndex : public pkgIndexFile
virtual bool Exists() const;
virtual bool HasPackages() const;
virtual unsigned long Size() const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const;
virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const;
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

debTranslationsIndex(string URI,string Dist,string Section, char const * const Language);


+ 6
- 2
apt-pkg/indexfile.h View File

@@ -74,8 +74,12 @@ class pkgIndexFile
virtual bool Exists() const = 0;
virtual bool HasPackages() const = 0;
virtual unsigned long Size() const = 0;
virtual bool Merge(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return false;};
virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return true;};
virtual bool Merge(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const { return false; };
__deprecated virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const
{ return Merge(Gen, &Prog); };
virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;};
__deprecated virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const
{return MergeFileProvides(Gen, &Prog);};
virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;

static bool TranslationsAvailable();


+ 28
- 17
apt-pkg/pkgcachegen.cc View File

@@ -526,7 +526,7 @@ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc,
// CacheGenerator::FinishCache - do various finish operations /*{{{*/
// ---------------------------------------------------------------------
/* This prepares the Cache for delivery */
bool pkgCacheGenerator::FinishCache(OpProgress &Progress)
bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
{
// FIXME: add progress reporting for this operation
// Do we have different architectures in your groups ?
@@ -923,7 +923,7 @@ static unsigned long ComputeSize(FileIterator Start,FileIterator End)
// ---------------------------------------------------------------------
/* */
static bool BuildCache(pkgCacheGenerator &Gen,
OpProgress &Progress,
OpProgress *Progress,
unsigned long &CurrentSize,unsigned long TotalSize,
FileIterator Start, FileIterator End)
{
@@ -944,7 +944,8 @@ static bool BuildCache(pkgCacheGenerator &Gen,
}
unsigned long Size = (*I)->Size();
Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists"));
if (Progress != NULL)
Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Reading package lists"));
CurrentSize += Size;
if ((*I)->Merge(Gen,Progress) == false)
@@ -953,13 +954,15 @@ static bool BuildCache(pkgCacheGenerator &Gen,

if (Gen.HasFileDeps() == true)
{
Progress.Done();
if (Progress != NULL)
Progress->Done();
TotalSize = ComputeSize(Start, End);
CurrentSize = 0;
for (I = Start; I != End; I++)
{
unsigned long Size = (*I)->Size();
Progress.OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides"));
if (Progress != NULL)
Progress->OverallProgress(CurrentSize,TotalSize,Size,_("Collecting File Provides"));
CurrentSize += Size;
if ((*I)->MergeFileProvides(Gen,Progress) == false)
return false;
@@ -969,7 +972,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
return true;
}
/*}}}*/
// MakeStatusCache - Construct the status cache /*{{{*/
// CacheGenerator::MakeStatusCache - Construct the status cache /*{{{*/
// ---------------------------------------------------------------------
/* This makes sure that the status cache (the cache that has all
index files from the sources list and all local ones) is ready
@@ -977,7 +980,10 @@ static bool BuildCache(pkgCacheGenerator &Gen,
the cache will be stored there. This is pretty much mandetory if you
are using AllowMem. AllowMem lets the function be run as non-root
where it builds the cache 'fast' into a memory buffer. */
bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
__deprecated bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
MMap **OutMap, bool AllowMem)
{ return pkgCacheGenerator::MakeStatusCache(List, &Progress, OutMap, AllowMem); }
bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
MMap **OutMap,bool AllowMem)
{
bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
@@ -1028,13 +1034,15 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,

if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
Progress.OverallProgress(0,1,1,_("Reading package lists"));

if (Progress != NULL)
Progress->OverallProgress(0,1,1,_("Reading package lists"));

// Cache is OK, Fin.
if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
{
Progress.OverallProgress(1,1,1,_("Reading package lists"));
if (Progress != NULL)
Progress->OverallProgress(1,1,1,_("Reading package lists"));
if (Debug == true)
std::clog << "pkgcache.bin is valid - no need to build anything" << std::endl;
return true;
@@ -1084,7 +1092,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());

// Build the status cache
pkgCacheGenerator Gen(Map.Get(),&Progress);
pkgCacheGenerator Gen(Map.Get(),Progress);
if (_error->PendingError() == true)
return false;
if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
@@ -1101,7 +1109,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
TotalSize = ComputeSize(Files.begin(),Files.end());
// Build the source cache
pkgCacheGenerator Gen(Map.Get(),&Progress);
pkgCacheGenerator Gen(Map.Get(),Progress);
if (_error->PendingError() == true)
return false;
if (BuildCache(Gen,Progress,CurrentSize,TotalSize,
@@ -1160,10 +1168,12 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
return true;
}
/*}}}*/
// MakeOnlyStatusCache - Build a cache with just the status files /*{{{*/
// CacheGenerator::MakeOnlyStatusCache - Build only a status files cache/*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap)
__deprecated bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap)
{ return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); }
bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap)
{
unsigned long MapSize = _config->FindI("APT::Cache-Limit",20*1024*1024);
vector<pkgIndexFile *> Files;
@@ -1178,8 +1188,9 @@ bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap)
TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
// Build the status cache
Progress.OverallProgress(0,1,1,_("Reading package lists"));
pkgCacheGenerator Gen(Map.Get(),&Progress);
if (Progress != NULL)
Progress->OverallProgress(0,1,1,_("Reading package lists"));
pkgCacheGenerator Gen(Map.Get(),Progress);
if (_error->PendingError() == true)
return false;
if (BuildCache(Gen,Progress,CurrentSize,TotalSize,


+ 8
- 2
apt-pkg/pkgcachegen.h View File

@@ -76,7 +76,11 @@ class pkgCacheGenerator /*{{{*/

bool HasFileDeps() {return FoundFileDeps;};
bool MergeFileProvides(ListParser &List);
bool FinishCache(OpProgress &Progress);
bool FinishCache(OpProgress *Progress);

static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
MMap **OutMap = 0,bool AllowMem = false);
static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);

pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
~pkgCacheGenerator();
@@ -134,10 +138,12 @@ class pkgCacheGenerator::ListParser
virtual ~ListParser() {};
};
/*}}}*/

bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
MMap **OutMap = 0,bool AllowMem = false);
bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);


#ifdef APT_COMPATIBILITY
#if APT_COMPATIBILITY != 986
#warning "Using APT_COMPATIBILITY"
@@ -145,7 +151,7 @@ bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
{
MMap *Map = 0;
if (pkgMakeStatusCache(List,Progress,&Map,true) == false)
if (pkgCacheGenerator::MakeStatusCache(List,&Progress,&Map,true) == false)
return 0;
return Map;
}


+ 3
- 0
debian/changelog View File

@@ -32,6 +32,9 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low
- get the best matching arch package from a group with FindPreferredPkg
* cmdline/apt-cache.cc:
- make the search multiarch compatible by using GrpIterator instead
* apt-pkg/cachefile.{cc,h}:
- split Open() into submethods to be able to build only parts
- make the OpProgress optional in the Cache buildprocess

-- David Kalnischkies <kalnischkies@gmail.com> Mon, 31 May 2010 22:36:35 +0200



Loading…
Cancel
Save