X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/350d30d24fee9a1aa5fedc7a30e7416999653417..7d19ee92f2368a40e739cb27d22d6d28f37ebf45:/apt-pkg/pkgcachegen.cc diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index ef7afda94..61f7a1124 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include #include @@ -59,14 +57,15 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : Map(*pMap), Cache(pMap,false), Progress(Prog), CurrentRlsFile(NULL), CurrentFile(NULL), d(NULL) { - if (_error->PendingError() == true) - return; - if (Map.Size() == 0) { // Setup the map interface.. Cache.HeaderP = (pkgCache::Header *)Map.Data(); - if (Map.RawAllocate(sizeof(pkgCache::Header)) == 0 && _error->PendingError() == true) + _error->PushToStack(); + Map.RawAllocate(sizeof(pkgCache::Header)); + bool const newError = _error->PendingError(); + _error->MergeWithStack(); + if (newError) return; Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0])); @@ -126,7 +125,7 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : advoid a problem during a crash */ pkgCacheGenerator::~pkgCacheGenerator() { - if (_error->PendingError() == true) + if (_error->PendingError() == true || Map.validData() == false) return; if (Map.Sync() == false) return; @@ -384,7 +383,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator // Add a new version map_pointer_t const verindex = NewVersion(Ver, Version, Pkg.Index(), Hash, *LastVer); - if (verindex == 0 && _error->PendingError()) + if (unlikely(verindex == 0)) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewVersion", 1); @@ -472,7 +471,7 @@ bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterato Dynamic DynDesc(Desc); map_pointer_t const descindex = NewDescription(Desc, lang, CurMd5, md5idx); - if (unlikely(descindex == 0 && _error->PendingError())) + if (unlikely(descindex == 0)) return _error->Error(_("Error occurred while processing %s (%s%d)"), Ver.ParentPkg().Name(), "NewDescription", 1); @@ -574,21 +573,31 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name if (APT::Configuration::checkArchitecture(Pkg.Arch()) == true) { pkgCache::PkgIterator const M = Grp.FindPreferredPkg(false); // native or any foreign pkg will do - if (M.end() == false) - for (pkgCache::PrvIterator Prv = M.ProvidesList(); Prv.end() == false; ++Prv) + if (M.end() == false) { + pkgCache::PrvIterator Prv; + Dynamic DynPrv(Prv); + for (Prv = M.ProvidesList(); Prv.end() == false; ++Prv) { if ((Prv->Flags & pkgCache::Flag::ArchSpecific) != 0) continue; pkgCache::VerIterator Ver = Prv.OwnerVer(); + Dynamic DynVer(Ver); if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed || ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign && (Prv->Flags & pkgCache::Flag::MultiArchImplicit) == 0)) if (NewProvides(Ver, Pkg, Prv->ProvideVersion, Prv->Flags) == false) return false; } + } + - for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) - for (pkgCache::VerIterator Ver = P.VersionList(); Ver.end() == false; ++Ver) + pkgCache::PkgIterator P; + pkgCache::VerIterator Ver; + Dynamic DynP(P); + Dynamic DynVer(Ver); + + for (P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) + for (Ver = P.VersionList(); Ver.end() == false; ++Ver) if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) if (NewProvides(Ver, Pkg, Ver->VerStr, pkgCache::Flag::MultiArchImplicit) == false) return false; @@ -596,8 +605,10 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name // and negative dependencies, don't forget negative dependencies { pkgCache::PkgIterator const M = Grp.FindPreferredPkg(false); - if (M.end() == false) - for (pkgCache::DepIterator Dep = M.RevDependsList(); Dep.end() == false; ++Dep) + if (M.end() == false) { + pkgCache::DepIterator Dep; + Dynamic DynDep(Dep); + for (Dep = M.RevDependsList(); Dep.end() == false; ++Dep) { if ((Dep->CompareOp & (pkgCache::Dep::ArchSpecific | pkgCache::Dep::MultiArchImplicit)) != 0) continue; @@ -605,10 +616,12 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name Dep->Type != pkgCache::Dep::Replaces) continue; pkgCache::VerIterator Ver = Dep.ParentVer(); + Dynamic DynVer(Ver); map_pointer_t * unused = NULL; if (NewDepends(Pkg, Ver, Dep->Version, Dep->CompareOp, Dep->Type, unused) == false) return false; } + } } // this package is the new last package @@ -617,6 +630,37 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name LastPkg->NextPackage = Package; } Grp->LastPackage = Package; + + // lazy-create foo (of amd64) provides foo:amd64 at the time we first need it + if (Arch == "any") + { + size_t const found = Name.find(':'); + std::string const NameA = Name.substr(0, found); + std::string const ArchA = Name.substr(found + 1); + pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA); + if (PkgA.end() == false) + { + Dynamic DynPkgA(PkgA); + pkgCache::PrvIterator Prv = PkgA.ProvidesList(); + for (; Prv.end() == false; ++Prv) + { + if (Prv.IsMultiArchImplicit()) + continue; + pkgCache::VerIterator V = Prv.OwnerVer(); + if (ArchA != V.ParentPkg().Arch()) + continue; + if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false) + return false; + } + pkgCache::VerIterator V = PkgA.VersionList(); + Dynamic DynV(V); + for (; V.end() == false; ++V) + { + if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false) + return false; + } + } + } return true; } /*}}}*/ @@ -1026,7 +1070,8 @@ bool pkgCacheListParser::NewProvides(pkgCache::VerIterator &Ver, // We do not add self referencing provides if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() || - (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0))) + (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0)) && + (Version.empty() || Version == Ver.VerStr())) return true; // Locate the target package @@ -1073,7 +1118,9 @@ bool pkgCacheGenerator::NewProvides(pkgCache::VerIterator &Ver, bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package, string const &Version, uint8_t const Flags) { pkgCache &Cache = Owner->Cache; - pkgCache::GrpIterator const Grp = Cache.FindGrp(Package); + pkgCache::GrpIterator Grp = Cache.FindGrp(Package); + Dynamic DynGrp(Grp); + if (Grp.end() == true) return NewProvides(Ver, Package, Cache.NativeArch(), Version, Flags); else @@ -1087,8 +1134,11 @@ bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string c bool const isImplicit = (Flags & pkgCache::Flag::MultiArchImplicit) == pkgCache::Flag::MultiArchImplicit; bool const isArchSpecific = (Flags & pkgCache::Flag::ArchSpecific) == pkgCache::Flag::ArchSpecific; - pkgCache::PkgIterator const OwnerPkg = Ver.ParentPkg(); - for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) + pkgCache::PkgIterator OwnerPkg = Ver.ParentPkg(); + Dynamic DynOwnerPkg(OwnerPkg); + pkgCache::PkgIterator Pkg; + Dynamic DynPkg(Pkg); + for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) { if (isImplicit && OwnerPkg == Pkg) continue; @@ -1226,12 +1276,18 @@ map_stringitem_t pkgCacheGenerator::StoreString(enum StringType const type, cons /* This just verifies that each file in the list of index files exists, has matching attributes with the cache and the cache does not have any extra files. */ +class APT_HIDDEN ScopedErrorRevert { +public: + ScopedErrorRevert() { _error->PushToStack(); } + ~ScopedErrorRevert() { _error->RevertToStack(); } +}; static bool CheckValidity(const string &CacheFile, pkgSourceList &List, FileIterator const Start, FileIterator const End, MMap **OutMap = 0) { + ScopedErrorRevert ser; bool const Debug = _config->FindB("Debug::pkgCacheGen", false); // No file, certainly invalid if (CacheFile.empty() == true || FileExists(CacheFile) == false) @@ -1250,18 +1306,19 @@ static bool CheckValidity(const string &CacheFile, // Map it FileFd CacheF(CacheFile,FileFd::ReadOnly); - SPtr Map = new MMap(CacheF,0); - pkgCache Cache(Map); - if (_error->PendingError() == true || Map->Size() == 0) + std::unique_ptr Map(new MMap(CacheF,0)); + if (unlikely(Map->validData()) == false) + return false; + pkgCache Cache(Map.get()); + if (_error->PendingError() || Map->Size() == 0) { if (Debug == true) std::clog << "Errors are pending or Map is empty() for " << CacheFile << std::endl; - _error->Discard(); return false; } - SPtrArray RlsVisited = new bool[Cache.HeaderP->ReleaseFileCount]; - memset(RlsVisited,0,sizeof(*RlsVisited)*Cache.HeaderP->ReleaseFileCount); + std::unique_ptr RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]); + memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount); std::vector Files; for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i) { @@ -1295,8 +1352,8 @@ static bool CheckValidity(const string &CacheFile, /* Now we check every index file, see if it is in the cache, verify the IMS data and check that it is on the disk too.. */ - SPtrArray Visited = new bool[Cache.HeaderP->PackageFileCount]; - memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount); + std::unique_ptr Visited(new bool[Cache.HeaderP->PackageFileCount]); + memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount); for (std::vector::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile) { if (Debug == true) @@ -1335,14 +1392,13 @@ static bool CheckValidity(const string &CacheFile, if (Debug == true) { std::clog << "Validity failed because of pending errors:" << std::endl; - _error->DumpErrors(); + _error->DumpErrors(std::clog, GlobalError::DEBUG, false); } - _error->Discard(); return false; } - + if (OutMap != 0) - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); return true; } /*}}}*/ @@ -1380,7 +1436,6 @@ static bool BuildCache(pkgCacheGenerator &Gen, pkgSourceList const * const List, FileIterator const Start, FileIterator const End) { - std::vector Files; bool mergeFailure = false; auto const indexFileMerge = [&](pkgIndexFile * const I) { @@ -1463,7 +1518,7 @@ static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * con std::string const &FileName) { FileFd SCacheF(FileName, FileFd::WriteAtomic); - if (_error->PendingError() == true) + if (SCacheF.IsOpen() == false || SCacheF.Failed()) return false; fchmod(SCacheF.Fd(),0644); @@ -1483,24 +1538,32 @@ static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * con return true; } static bool loadBackMMapFromFile(std::unique_ptr &Gen, - SPtr &Map, OpProgress * const Progress, std::string const &FileName) + std::unique_ptr &Map, OpProgress * const Progress, std::string const &FileName) { - Map = CreateDynamicMMap(NULL, 0); + Map.reset(CreateDynamicMMap(NULL, 0)); + if (unlikely(Map->validData()) == false) + return false; FileFd CacheF(FileName, FileFd::ReadOnly); + if (CacheF.IsOpen() == false || CacheF.Failed()) + return false; + _error->PushToStack(); map_pointer_t const alloc = Map->RawAllocate(CacheF.Size()); - if ((alloc == 0 && _error->PendingError()) - || CacheF.Read((unsigned char *)Map->Data() + alloc, - CacheF.Size()) == false) + bool const newError = _error->PendingError(); + _error->MergeWithStack(); + if (alloc == 0 && newError) + return false; + if (CacheF.Read((unsigned char *)Map->Data() + alloc, CacheF.Size()) == false) return false; - Gen.reset(new pkgCacheGenerator(Map.Get(),Progress)); + Gen.reset(new pkgCacheGenerator(Map.get(),Progress)); return true; } -APT_DEPRECATED bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, +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) + MMap **OutMap,bool) { + // FIXME: deprecate the ignored AllowMem parameter bool const Debug = _config->FindB("Debug::pkgCacheGen", false); std::vector Files; @@ -1565,20 +1628,12 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress if (Debug == true) std::clog << "Do we have write-access to the cache files? " << (Writeable ? "YES" : "NO") << std::endl; - - if (Writeable == false && AllowMem == false) - { - if (CacheFile.empty() == false) - return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str()); - else if (SrcCacheFile.empty() == false) - return _error->Error(_("Unable to write to %s"),flNotFile(SrcCacheFile).c_str()); - else - return _error->Error("Unable to create caches as file usage is disabled, but memory not allowed either!"); - } } // At this point we know we need to construct something, so get storage ready - SPtr Map = CreateDynamicMMap(NULL, 0); + std::unique_ptr Map(CreateDynamicMMap(NULL, 0)); + if (unlikely(Map->validData()) == false) + return false; if (Debug == true) std::clog << "Open memory Map (not filebased)" << std::endl; @@ -1599,7 +1654,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress { if (Debug == true) std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl; - Gen.reset(new pkgCacheGenerator(Map.Get(),Progress)); + Gen.reset(new pkgCacheGenerator(Map.get(),Progress)); TotalSize += ComputeSize(&List, Files.begin(),Files.end()); if (BuildCache(*Gen, Progress, CurrentSize, TotalSize, &List, @@ -1607,7 +1662,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress return false; if (Writeable == true && SrcCacheFile.empty() == false) - if (writeBackMMapToFile(Gen.get(), Map.Get(), SrcCacheFile) == false) + if (writeBackMMapToFile(Gen.get(), Map.get(), SrcCacheFile) == false) return false; } @@ -1620,7 +1675,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress return false; if (Writeable == true && CacheFile.empty() == false) - if (writeBackMMapToFile(Gen.get(), Map.Get(), CacheFile) == false) + if (writeBackMMapToFile(Gen.get(), Map.get(), CacheFile) == false) return false; } @@ -1644,7 +1699,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress } if (OutMap != nullptr) - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); if (Debug == true) std::clog << "Everything is ready for shipping" << std::endl; @@ -1652,9 +1707,12 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress } /*}}}*/ // CacheGenerator::MakeOnlyStatusCache - Build only a status files cache/*{{{*/ -// --------------------------------------------------------------------- -/* */ -APT_DEPRECATED bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) +class APT_HIDDEN ScopedErrorMerge { +public: + ScopedErrorMerge() { _error->PushToStack(); } + ~ScopedErrorMerge() { _error->MergeWithStack(); } +}; +bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap) { return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); } bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap) { @@ -1662,16 +1720,18 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O if (_system->AddStatusFiles(Files) == false) return false; - SPtr Map = CreateDynamicMMap(NULL, 0); + ScopedErrorMerge sem; + std::unique_ptr Map(CreateDynamicMMap(NULL, 0)); + if (unlikely(Map->validData()) == false) + return false; map_filesize_t CurrentSize = 0; map_filesize_t TotalSize = 0; - TotalSize = ComputeSize(NULL, Files.begin(), Files.end()); - + // Build the status cache if (Progress != NULL) Progress->OverallProgress(0,1,1,_("Reading package lists")); - pkgCacheGenerator Gen(Map.Get(),Progress); + pkgCacheGenerator Gen(Map.get(),Progress); if (_error->PendingError() == true) return false; if (BuildCache(Gen,Progress,CurrentSize,TotalSize, NULL, @@ -1680,7 +1740,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O if (_error->PendingError() == true) return false; - *OutMap = Map.UnGuard(); + *OutMap = Map.release(); return true; }