X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/88a8975f156e452d9f3ebe76822b236e8962ebba..530302ef25d14bd7577f18cf98c2fa868c3c1dd3:/apt-pkg/pkgcachegen.cc diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 6daebbc2a..6e307fba9 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -49,6 +49,7 @@ static bool IsDuplicateDescription(pkgCache::DescIterator Desc, MD5SumValue const &CurMd5, std::string const &CurLang); using std::string; +using APT::StringView; // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -57,14 +58,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])); @@ -100,6 +102,8 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) : else Cache.HeaderP->SetArchitectures(idxArchitecture); + // Calculate the hash for the empty map, so ReMap does not fail + Cache.HeaderP->CacheFileSize = Cache.CacheHash(); Cache.ReMap(); } else @@ -124,17 +128,20 @@ 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; Cache.HeaderP->Dirty = false; - Cache.HeaderP->CacheFileSize = Map.Size(); + Cache.HeaderP->CacheFileSize = Cache.CacheHash(); + + if (_config->FindB("Debug::pkgCacheGen", false)) + std::clog << "Produced cache with hash " << Cache.HeaderP->CacheFileSize << std::endl; Map.Sync(0,sizeof(pkgCache::Header)); } /*}}}*/ -void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap) {/*{{{*/ +void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap, size_t oldSize) {/*{{{*/ if (oldMap == newMap) return; @@ -170,31 +177,42 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReMap(oldMap, newMap); + for (APT::StringView* ViewP : Dynamic::toReMap) { + // Ignore views outside of the cache. + if (ViewP->data() < static_cast(oldMap) + || ViewP->data() > static_cast(oldMap) + oldSize) + continue; + const char *data = ViewP->data() + (static_cast(newMap) - static_cast(oldMap)); + *ViewP = StringView(data , ViewP->size()); + } } /*}}}*/ // CacheGenerator::WriteStringInMap /*{{{*/ map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String, const unsigned long &Len) { + size_t oldSize = Map.Size(); void const * const oldMap = Map.Data(); map_stringitem_t const index = Map.WriteString(String, Len); if (index != 0) - ReMap(oldMap, Map.Data()); + ReMap(oldMap, Map.Data(), oldSize); return index; } /*}}}*/ // CacheGenerator::WriteStringInMap /*{{{*/ map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String) { + size_t oldSize = Map.Size(); void const * const oldMap = Map.Data(); map_stringitem_t const index = Map.WriteString(String); if (index != 0) - ReMap(oldMap, Map.Data()); + ReMap(oldMap, Map.Data(), oldSize); return index; } /*}}}*/ map_pointer_t pkgCacheGenerator::AllocateInMap(const unsigned long &size) {/*{{{*/ + size_t oldSize = Map.Size(); void const * const oldMap = Map.Data(); map_pointer_t const index = Map.Allocate(size); if (index != 0) - ReMap(oldMap, Map.Data()); + ReMap(oldMap, Map.Data(), oldSize); return index; } /*}}}*/ @@ -301,8 +319,6 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator // Find the right version to write the description MD5SumValue CurMd5 = List.Description_md5(); - if (CurMd5.Value().empty() == true && List.Description("").empty() == true) - return true; std::vector availDesc = List.AvailableDescriptionLanguages(); for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { @@ -382,7 +398,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); @@ -437,8 +453,6 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator /* Record the Description(s) based on their master md5sum */ MD5SumValue CurMd5 = List.Description_md5(); - if (CurMd5.Value().empty() == true && List.Description("").empty() == true) - return true; /* Before we add a new description we first search in the group for a version with a description of the same MD5 - if so we reuse this @@ -470,7 +484,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); @@ -495,8 +509,9 @@ bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterato // CacheGenerator::NewGroup - Add a new group /*{{{*/ // --------------------------------------------------------------------- /* This creates a new group structure and adds it to the hash table */ -bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name) +bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name) { + Dynamic DName(Name); Grp = Cache.FindGrp(Name); if (Grp.end() == false) return true; @@ -515,7 +530,8 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name) // Insert it into the hash table unsigned long const Hash = Cache.Hash(Name); map_pointer_t *insertAt = &Cache.HeaderP->GrpHashTableP()[Hash]; - while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + *insertAt)->Name) > 0) + + while (*insertAt != 0 && Name.compare(Cache.ViewString((Cache.GrpP + *insertAt)->Name)) > 0) insertAt = &(Cache.GrpP + *insertAt)->Next; Grp->Next = *insertAt; *insertAt = Group; @@ -527,9 +543,11 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name) // CacheGenerator::NewPackage - Add a new package /*{{{*/ // --------------------------------------------------------------------- /* This creates a new package structure and adds it to the hash table */ -bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name, - const string &Arch) { +bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name, + StringView Arch) { pkgCache::GrpIterator Grp; + Dynamic DName(Name); + Dynamic DArch(Arch); Dynamic DynGrp(Grp); if (unlikely(NewGroup(Grp, Name) == false)) return false; @@ -561,41 +579,61 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name // Insert it into the hash table map_id_t const Hash = Cache.Hash(Name); map_pointer_t *insertAt = &Cache.HeaderP->PkgHashTableP()[Hash]; - while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0) + while (*insertAt != 0 && Name.compare(Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0) insertAt = &(Cache.PkgP + *insertAt)->NextPackage; Pkg->NextPackage = *insertAt; *insertAt = Package; } else // Group the Packages together { - // but first get implicit provides done - if (APT::Configuration::checkArchitecture(Pkg.Arch()) == true) + // if sibling is provided by another package, this one is too { 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 (APT::Configuration::checkArchitecture(Ver.ParentPkg().Arch()) == false) + continue; if (NewProvides(Ver, Pkg, Prv->ProvideVersion, Prv->Flags) == false) return false; + } } + } + } + // let M-A:foreign package siblings provide this package + { + pkgCache::PkgIterator P; + pkgCache::VerIterator Ver; + Dynamic DynP(P); + Dynamic DynVer(Ver); - for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) - for (pkgCache::VerIterator Ver = P.VersionList(); Ver.end() == false; ++Ver) + for (P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) + { + if (APT::Configuration::checkArchitecture(P.Arch()) == false) + continue; + 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; + } } // 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; @@ -603,10 +641,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 @@ -615,6 +655,52 @@ 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(':'); + StringView ArchA = Name.substr(found + 1); + if (ArchA != "any") + { + // ArchA is used inside the loop which might remap (NameA is not used) + Dynamic DynArchA(ArchA); + StringView NameA = Name.substr(0, found); + pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA); + Dynamic DynPkgA(PkgA); + if (PkgA.end()) + { + Dynamic DynNameA(NameA); + if (NewPackage(PkgA, NameA, ArchA) == false) + return false; + } + if (unlikely(PkgA.end())) + return _error->Fatal("NewPackage was successful for %s:%s," + "but the package doesn't exist anyhow!", + NameA.to_string().c_str(), ArchA.to_string().c_str()); + else + { + 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; } /*}}}*/ @@ -946,14 +1032,17 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, /* This creates a Group and the Package to link this dependency to if needed and handles also the caching of the old endpoint */ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver, - const string &PackageName, - const string &Arch, - const string &Version, + StringView PackageName, + StringView Arch, + StringView Version, uint8_t const Op, uint8_t const Type) { pkgCache::GrpIterator Grp; Dynamic DynGrp(Grp); + Dynamic DynPackageName(PackageName); + Dynamic DynArch(Arch); + Dynamic DynVersion(Version); if (unlikely(Owner->NewGroup(Grp, PackageName) == false)) return false; @@ -962,7 +1051,7 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver, { int const CmpOp = Op & 0x0F; // =-deps are used (79:1) for lockstep on same-source packages (e.g. data-packages) - if (CmpOp == pkgCache::Dep::Equals && strcmp(Version.c_str(), Ver.VerStr()) == 0) + if (CmpOp == pkgCache::Dep::Equals && Version == Ver.VerStr()) idxVersion = Ver->VerStr; if (idxVersion == 0) @@ -1015,16 +1104,20 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver, /*}}}*/ // ListParser::NewProvides - Create a Provides element /*{{{*/ bool pkgCacheListParser::NewProvides(pkgCache::VerIterator &Ver, - const string &PkgName, - const string &PkgArch, - const string &Version, + StringView PkgName, + StringView PkgArch, + StringView Version, uint8_t const Flags) { pkgCache const &Cache = Owner->Cache; + Dynamic DynPkgName(PkgName); + Dynamic DynArch(PkgArch); + Dynamic DynVersion(Version); // 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 @@ -1068,10 +1161,14 @@ bool pkgCacheGenerator::NewProvides(pkgCache::VerIterator &Ver, } /*}}}*/ // ListParser::NewProvidesAllArch - add provides for all architectures /*{{{*/ -bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package, - string const &Version, uint8_t const Flags) { +bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, StringView Package, + StringView 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); + Dynamic DynPackage(Package); + Dynamic DynVersion(Version); + if (Grp.end() == true) return NewProvides(Ver, Package, Cache.NativeArch(), Version, Flags); else @@ -1085,8 +1182,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; @@ -1199,23 +1299,21 @@ bool pkgCacheGenerator::SelectFile(std::string const &File, map_stringitem_t pkgCacheGenerator::StoreString(enum StringType const type, const char *S, unsigned int Size) { - std::string const key(S, Size); - - std::map * strings; + auto strings = &strMixed; switch(type) { case MIXED: strings = &strMixed; break; case PKGNAME: strings = &strPkgNames; break; case VERSIONNUMBER: strings = &strVersions; break; case SECTION: strings = &strSections; break; - default: _error->Fatal("Unknown enum type used for string storage of '%s'", key.c_str()); return 0; + default: _error->Fatal("Unknown enum type used for string storage of '%.*s'", Size, S); return 0; } - std::map::const_iterator const item = strings->find(key); + auto const item = strings->find({S, Size, nullptr, 0}); if (item != strings->end()) - return item->second; + return item->item; map_stringitem_t const idxString = WriteStringInMap(S,Size); - strings->insert(std::make_pair(key, idxString)); + strings->insert({nullptr, Size, this, idxString}); return idxString; } /*}}}*/ @@ -1224,12 +1322,19 @@ 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) + MMap **OutMap = 0, + pkgCache **OutCache = 0) { + ScopedErrorRevert ser; bool const Debug = _config->FindB("Debug::pkgCacheGen", false); // No file, certainly invalid if (CacheFile.empty() == true || FileExists(CacheFile) == false) @@ -1249,12 +1354,14 @@ static bool CheckValidity(const string &CacheFile, // Map it FileFd CacheF(CacheFile,FileFd::ReadOnly); std::unique_ptr Map(new MMap(CacheF,0)); - pkgCache Cache(Map.get()); - if (_error->PendingError() == true || Map->Size() == 0) + if (unlikely(Map->validData()) == false) + return false; + std::unique_ptr CacheP(new pkgCache(Map.get())); + pkgCache &Cache = *CacheP.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; } @@ -1333,14 +1440,15 @@ 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.release(); + if (OutCache != 0) + *OutCache = CacheP.release(); return true; } /*}}}*/ @@ -1378,7 +1486,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) { @@ -1461,7 +1568,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); @@ -1469,36 +1576,48 @@ static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * con // Write out the main data if (SCacheF.Write(Map->Data(),Map->Size()) == false) return _error->Error(_("IO Error saving source cache")); - SCacheF.Sync(); // Write out the proper header Gen->GetCache().HeaderP->Dirty = false; + Gen->GetCache().HeaderP->CacheFileSize = Gen->GetCache().CacheHash(); if (SCacheF.Seek(0) == false || SCacheF.Write(Map->Data(),sizeof(*Gen->GetCache().HeaderP)) == false) return _error->Error(_("IO Error saving source cache")); Gen->GetCache().HeaderP->Dirty = true; - SCacheF.Sync(); return true; } static bool loadBackMMapFromFile(std::unique_ptr &Gen, std::unique_ptr &Map, OpProgress * const Progress, std::string const &FileName) { 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)); 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) +{ + return pkgCacheGenerator::MakeStatusCache(List, Progress, OutMap, nullptr, true); +} +bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress, + MMap **OutMap,pkgCache **OutCache, bool) { + // FIXME: deprecate the ignored AllowMem parameter bool const Debug = _config->FindB("Debug::pkgCacheGen", false); std::vector Files; @@ -1529,7 +1648,8 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress bool srcpkgcache_fine = false; bool volatile_fine = List.GetVolatileFiles().empty(); - if (CheckValidity(CacheFile, List, Files.begin(), Files.end(), volatile_fine ? OutMap : NULL) == true) + if (CheckValidity(CacheFile, List, Files.begin(), Files.end(), volatile_fine ? OutMap : NULL, + volatile_fine ? OutCache : NULL) == true) { if (Debug == true) std::clog << "pkgcache.bin is valid - no need to build any cache" << std::endl; @@ -1563,20 +1683,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 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; @@ -1650,9 +1762,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) { @@ -1660,12 +1775,14 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O if (_system->AddStatusFiles(Files) == false) return false; + 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"));