X-Git-Url: https://git.saurik.com/apt-legacy.git/blobdiff_plain/acdafb440bd086fdb81bd61e03d5c89b057f0f6c..a9359695769d43f745dc5243d1044981e03555d5:/apt-pkg/pkgcachegen.cc diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 1b53649..48a7976 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -32,7 +33,8 @@ #include #include #include -#include + +#include /*}}}*/ typedef vector::iterator FileIterator; @@ -53,14 +55,16 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : { // Setup the map interface.. Cache.HeaderP = (pkgCache::Header *)Map.Data(); - Map.RawAllocate(sizeof(pkgCache::Header)); + if (Map.RawAllocate(sizeof(pkgCache::Header)) == 0 && _error->PendingError() == true) + return; + Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0])); - + // Starting header *Cache.HeaderP = pkgCache::Header(); Cache.HeaderP->VerSysName = Map.WriteString(_system->VS->Label); Cache.HeaderP->Architecture = Map.WriteString(_config->Find("APT::Architecture")); - Cache.ReMap(); + Cache.ReMap(); } else { @@ -101,26 +105,37 @@ bool pkgCacheGenerator::MergeList(ListParser &List, pkgCache::VerIterator *OutVer) { List.Owner = this; + debListParser *debian(dynamic_cast(&List)); unsigned int Counter = 0; while (List.Step() == true) { // Get a pointer to the package structure - string PackageName = List.Package(); + srkString PackageName; + if (debian != NULL) + PackageName = debian->Find("Package"); + else + PackageName = List.Package(); if (PackageName.empty() == true) return false; pkgCache::PkgIterator Pkg; if (NewPackage(Pkg,PackageName) == false) - return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str()); + return _error->Error(_("Error occurred while processing %s (NewPackage)"),std::string(PackageName).c_str()); Counter++; if (Counter % 100 == 0 && Progress != 0) Progress->Progress(List.Offset()); + string language(List.DescriptionLanguage()); + /* Get a pointer to the version structure. We know the list is sorted so we use that fact in the search. Insertion of new versions is done with correct sorting */ - string Version = List.Version(); + srkString Version; + if (debian != NULL) + Version = debian->Find("Version"); + else + Version = List.Version(); if (Version.empty() == true) { // we first process the package, then the descriptions @@ -128,14 +143,14 @@ bool pkgCacheGenerator::MergeList(ListParser &List, // of MMap space) if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false) return _error->Error(_("Error occurred while processing %s (UsePackage1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Find the right version to write the description MD5SumValue CurMd5 = List.Description_md5(); pkgCache::VerIterator Ver = Pkg.VersionList(); map_ptrloc *LastVer = &Pkg->VersionList; - for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++) + for (; Ver.end() == false; LastVer = &Ver->NextVer, Ver++) { pkgCache::DescIterator Desc = Ver.DescriptionList(); map_ptrloc *LastDesc = &Ver->DescriptionList; @@ -143,25 +158,25 @@ bool pkgCacheGenerator::MergeList(ListParser &List, // don't add a new description if we have one for the given // md5 && language - for ( ; Desc.end() == false; Desc++) + for ( ; Desc.end() == false; Desc++) if (MD5SumValue(Desc.md5()) == CurMd5 && - Desc.LanguageCode() == List.DescriptionLanguage()) + Desc.LanguageCode() == language) duplicate=true; if(duplicate) continue; for (Desc = Ver.DescriptionList(); - Desc.end() == false; + Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++) { if (MD5SumValue(Desc.md5()) == CurMd5) { // Add new description - *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc); + *LastDesc = NewDescription(Desc, language, CurMd5, *LastDesc); Desc->ParentPkg = Pkg.Index(); - if (NewFileDesc(Desc,List) == false) - return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),PackageName.c_str()); + if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) + return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),std::string(PackageName).c_str()); break; } } @@ -187,11 +202,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, { if (List.UsePackage(Pkg,Ver) == false) return _error->Error(_("Error occurred while processing %s (UsePackage2)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (NewFileVer(Ver,List) == false) return _error->Error(_("Error occurred while processing %s (NewFileVer1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Read only a single record and return if (OutVer != 0) @@ -220,17 +235,17 @@ bool pkgCacheGenerator::MergeList(ListParser &List, Ver->ParentPkg = Pkg.Index(); Ver->Hash = Hash; - if (List.NewVersion(Ver) == false) + if ((*LastVer == 0 && _error->PendingError()) || List.NewVersion(Ver) == false) return _error->Error(_("Error occurred while processing %s (NewVersion1)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (List.UsePackage(Pkg,Ver) == false) return _error->Error(_("Error occurred while processing %s (UsePackage3)"), - PackageName.c_str()); + std::string(PackageName).c_str()); if (NewFileVer(Ver,List) == false) return _error->Error(_("Error occurred while processing %s (NewVersion2)"), - PackageName.c_str()); + std::string(PackageName).c_str()); // Read only a single record and return if (OutVer != 0) @@ -249,11 +264,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, for (; Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++); // Add new description - *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), List.Description_md5(), *LastDesc); + *LastDesc = NewDescription(Desc, language, List.Description_md5(), *LastDesc); Desc->ParentPkg = Pkg.Index(); - if (NewFileDesc(Desc,List) == false) - return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str()); + if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false) + return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),std::string(PackageName).c_str()); } FoundFileDeps |= List.HasFileDeps(); @@ -325,6 +340,11 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List) // --------------------------------------------------------------------- /* This creates a new package structure and adds it to the hash table */ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name) +{ + return NewPackage(Pkg, srkString(Name)); +} + +bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const srkString &Name) { Pkg = Cache.FindPkg(Name); if (Pkg.end() == false) @@ -343,7 +363,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name Cache.HeaderP->HashTable[Hash] = Package; // Set the name and the ID - Pkg->Name = Map.WriteString(Name); + Pkg->Name = Map.WriteString(Name.Start,Name.Size); if (Pkg->Name == 0) return false; Pkg->ID = Cache.HeaderP->PackageCount++; @@ -390,6 +410,13 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, const string &VerStr, unsigned long Next) +{ + return NewVersion(Ver, srkString(VerStr), Next); +} + +unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, + const srkString &VerStr, + unsigned long Next) { // Get a structure unsigned long Version = Map.Allocate(sizeof(pkgCache::Version)); @@ -400,7 +427,7 @@ unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version); Ver->NextVer = Next; Ver->ID = Cache.HeaderP->VersionCount++; - Ver->VerStr = Map.WriteString(VerStr); + Ver->VerStr = Map.WriteString(VerStr.Start, VerStr.Size); if (Ver->VerStr == 0) return 0; @@ -419,7 +446,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, // Get a structure unsigned long DescFile = Map.Allocate(sizeof(pkgCache::DescFile)); if (DescFile == 0) - return 0; + return false; pkgCache::DescFileIterator DF(Cache,Cache.DescFileP + DescFile); DF->File = CurrentFile - Cache.PkgFileP; @@ -460,6 +487,8 @@ map_ptrloc pkgCacheGenerator::NewDescription(pkgCache::DescIterator &Desc, Desc->ID = Cache.HeaderP->DescriptionCount++; Desc->language_code = Map.WriteString(Lang); Desc->md5sum = Map.WriteString(md5sum.Value()); + if (Desc->language_code == 0 || Desc->md5sum == 0) + return 0; return Description; } @@ -473,6 +502,15 @@ bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, const string &Version, unsigned int Op, unsigned int Type) +{ + return NewDepends(Ver, srkString(PackageName), srkString(Version), Op, Type); +} + +bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, + const srkString &PackageName, + const srkString &Version, + unsigned int Op, + unsigned int Type) { pkgCache &Cache = Owner->Cache; @@ -536,6 +574,13 @@ bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver, bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver, const string &PackageName, const string &Version) +{ + return NewProvides(Ver, srkString(PackageName), srkString(Version)); +} + +bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver, + const srkString &PackageName, + const srkString &Version) { pkgCache &Cache = Owner->Cache; @@ -678,7 +723,6 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S, return ItemP->String; } /*}}}*/ - // CheckValidity - Check that a cache is up-to-date /*{{{*/ // --------------------------------------------------------------------- /* This just verifies that each file in the list of index files exists, @@ -687,16 +731,23 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S, static bool CheckValidity(const string &CacheFile, FileIterator Start, FileIterator End,MMap **OutMap = 0) { + bool const Debug = _config->FindB("Debug::pkgCacheGen", false); // No file, certainly invalid if (CacheFile.empty() == true || FileExists(CacheFile) == false) + { + if (Debug == true) + std::clog << "CacheFile doesn't exist" << std::endl; return false; - + } + // Map it FileFd CacheF(CacheFile,FileFd::ReadOnly); - SPtr Map = new MMap(CacheF,MMap::Public | MMap::ReadOnly); + SPtr Map = new MMap(CacheF,0); pkgCache Cache(Map); if (_error->PendingError() == true || Map->Size() == 0) { + if (Debug == true) + std::clog << "Errors are pending or Map is empty()" << std::endl; _error->Discard(); return false; } @@ -706,9 +757,15 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, SPtrArray Visited = new bool[Cache.HeaderP->PackageFileCount]; memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount); for (; Start != End; Start++) - { + { + if (Debug == true) + std::clog << "Checking PkgFile " << (*Start)->Describe() << ": "; if ((*Start)->HasPackages() == false) + { + if (Debug == true) + std::clog << "Has NO packages" << std::endl; continue; + } if ((*Start)->Exists() == false) { @@ -716,23 +773,40 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, _error->WarningE("stat",_("Couldn't stat source package list %s"), (*Start)->Describe().c_str()); #endif + if (Debug == true) + std::clog << "file doesn't exist" << std::endl; continue; } // FindInCache is also expected to do an IMS check. pkgCache::PkgFileIterator File = (*Start)->FindInCache(Cache); if (File.end() == true) + { + if (Debug == true) + std::clog << "FindInCache returned end-Pointer" << std::endl; return false; + } Visited[File->ID] = true; + if (Debug == true) + std::clog << "with ID " << File->ID << " is valid" << std::endl; } for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++) if (Visited[I] == false) + { + if (Debug == true) + std::clog << "File with ID" << I << " wasn't visited" << std::endl; return false; + } if (_error->PendingError() == true) { + if (Debug == true) + { + std::clog << "Validity failed because of pending errors:" << std::endl; + _error->DumpErrors(); + } _error->Discard(); return false; } @@ -819,7 +893,8 @@ static bool BuildCache(pkgCacheGenerator &Gen, bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, MMap **OutMap,bool AllowMem) { - unsigned long MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024); + bool const Debug = _config->FindB("Debug::pkgCacheGen", false); + unsigned long const MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024); vector Files; for (vector::const_iterator i = List.begin(); @@ -833,13 +908,13 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, Files.push_back (*j); } - unsigned long EndOfSource = Files.size(); + unsigned long const EndOfSource = Files.size(); if (_system->AddStatusFiles(Files) == false) return false; - + // Decide if we can write to the files.. - string CacheFile = _config->FindFile("Dir::Cache::pkgcache"); - string SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache"); + string const CacheFile = _config->FindFile("Dir::Cache::pkgcache"); + string const SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache"); // Decide if we can write to the cache bool Writeable = false; @@ -848,7 +923,9 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, else if (SrcCacheFile.empty() == false) Writeable = access(flNotFile(SrcCacheFile).c_str(),W_OK) == 0; - + if (Debug == true) + std::clog << "Do we have write-access to the cache files? " << (Writeable ? "YES" : "NO") << std::endl; + if (Writeable == false && AllowMem == false && CacheFile.empty() == false) return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str()); @@ -858,8 +935,12 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true) { 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; } + else if (Debug == true) + std::clog << "pkgcache.bin is NOT valid" << std::endl; /* At this point we know we need to reconstruct the package cache, begin. */ @@ -873,11 +954,15 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, Map = new DynamicMMap(*CacheF,MMap::Public,MapSize); if (_error->PendingError() == true) return false; + if (Debug == true) + std::clog << "Open filebased MMap" << std::endl; } else { // Just build it in memory.. - Map = new DynamicMMap(MMap::Public,MapSize); + Map = new DynamicMMap(0,MapSize); + if (Debug == true) + std::clog << "Open memory Map (not filebased)" << std::endl; } // Lets try the source cache. @@ -886,14 +971,18 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, if (CheckValidity(SrcCacheFile,Files.begin(), Files.begin()+EndOfSource) == true) { + if (Debug == true) + std::clog << "srcpkgcache.bin is valid - populate MMap with it." << std::endl; // Preload the map with the source cache FileFd SCacheF(SrcCacheFile,FileFd::ReadOnly); - if (SCacheF.Read((unsigned char *)Map->Data() + Map->RawAllocate(SCacheF.Size()), - SCacheF.Size()) == false) + unsigned long const alloc = Map->RawAllocate(SCacheF.Size()); + if ((alloc == 0 && _error->PendingError()) + || SCacheF.Read((unsigned char *)Map->Data() + alloc, + SCacheF.Size()) == false) return false; TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end()); - + // Build the status cache pkgCacheGenerator Gen(Map.Get(),&Progress); if (_error->PendingError() == true) @@ -904,6 +993,8 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, } else { + if (Debug == true) + std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl; TotalSize = ComputeSize(Files.begin(),Files.end()); // Build the source cache @@ -942,6 +1033,8 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, Files.begin()+EndOfSource,Files.end()) == false) return false; } + if (Debug == true) + std::clog << "Caches are ready for shipping" << std::endl; if (_error->PendingError() == true) return false; @@ -950,7 +1043,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, if (CacheF != 0) { delete Map.UnGuard(); - *OutMap = new MMap(*CacheF,MMap::Public | MMap::ReadOnly); + *OutMap = new MMap(*CacheF,0); } else { @@ -972,8 +1065,7 @@ bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) if (_system->AddStatusFiles(Files) == false) return false; - SPtr Map; - Map = new DynamicMMap(MMap::Public,MapSize); + SPtr Map = new DynamicMMap(0,MapSize); unsigned long CurrentSize = 0; unsigned long TotalSize = 0;