#include <apt-pkg/progress.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/sptr.h>
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/macros.h>
#include <apt-pkg/metaindex.h>
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]));
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;
// 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);
Dynamic<pkgCache::DescIterator> 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);
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<pkgCache::PrvIterator> DynPrv(Prv);
+ for (Prv = M.ProvidesList(); Prv.end() == false; ++Prv)
{
if ((Prv->Flags & pkgCache::Flag::ArchSpecific) != 0)
continue;
pkgCache::VerIterator Ver = Prv.OwnerVer();
+ Dynamic<pkgCache::VerIterator> 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<pkgCache::PkgIterator> DynP(P);
+ Dynamic<pkgCache::VerIterator> 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;
// 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<pkgCache::DepIterator> DynDep(Dep);
+ for (Dep = M.RevDependsList(); Dep.end() == false; ++Dep)
{
if ((Dep->CompareOp & (pkgCache::Dep::ArchSpecific | pkgCache::Dep::MultiArchImplicit)) != 0)
continue;
Dep->Type != pkgCache::Dep::Replaces)
continue;
pkgCache::VerIterator Ver = Dep.ParentVer();
+ Dynamic<pkgCache::VerIterator> 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
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<pkgCache::PkgIterator> 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<pkgCache::VerIterator> DynV(V);
+ for (; V.end() == false; ++V)
+ {
+ if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+ return false;
+ }
+ }
+ }
return true;
}
/*}}}*/
// 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
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<pkgCache::GrpIterator> DynGrp(Grp);
+
if (Grp.end() == true)
return NewProvides(Ver, Package, Cache.NativeArch(), Version, Flags);
else
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<pkgCache::PkgIterator> DynOwnerPkg(OwnerPkg);
+ pkgCache::PkgIterator Pkg;
+ Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
+ for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
{
if (isImplicit && OwnerPkg == Pkg)
continue;
/* 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)
// Map it
FileFd CacheF(CacheFile,FileFd::ReadOnly);
- SPtr<MMap> Map = new MMap(CacheF,0);
- pkgCache Cache(Map);
- if (_error->PendingError() == true || Map->Size() == 0)
+ std::unique_ptr<MMap> 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<bool> RlsVisited = new bool[Cache.HeaderP->ReleaseFileCount];
- memset(RlsVisited,0,sizeof(*RlsVisited)*Cache.HeaderP->ReleaseFileCount);
+ std::unique_ptr<bool[]> RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]);
+ memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount);
std::vector<pkgIndexFile *> Files;
for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i)
{
/* 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<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
- memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
+ std::unique_ptr<bool[]> Visited(new bool[Cache.HeaderP->PackageFileCount]);
+ memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount);
for (std::vector<pkgIndexFile *>::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile)
{
if (Debug == true)
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;
}
/*}}}*/
pkgSourceList const * const List,
FileIterator const Start, FileIterator const End)
{
- std::vector<pkgIndexFile *> Files;
bool mergeFailure = false;
auto const indexFileMerge = [&](pkgIndexFile * const I) {
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);
return true;
}
static bool loadBackMMapFromFile(std::unique_ptr<pkgCacheGenerator> &Gen,
- SPtr<DynamicMMap> &Map, OpProgress * const Progress, std::string const &FileName)
+ std::unique_ptr<DynamicMMap> &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<pkgIndexFile *> Files;
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<DynamicMMap> Map = CreateDynamicMMap(NULL, 0);
+ std::unique_ptr<DynamicMMap> Map(CreateDynamicMMap(NULL, 0));
+ if (unlikely(Map->validData()) == false)
+ return false;
if (Debug == true)
std::clog << "Open memory Map (not filebased)" << std::endl;
{
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,
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;
}
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;
}
}
if (OutMap != nullptr)
- *OutMap = Map.UnGuard();
+ *OutMap = Map.release();
if (Debug == true)
std::clog << "Everything is ready for shipping" << std::endl;
}
/*}}}*/
// 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)
{
if (_system->AddStatusFiles(Files) == false)
return false;
- SPtr<DynamicMMap> Map = CreateDynamicMMap(NULL, 0);
+ ScopedErrorMerge sem;
+ std::unique_ptr<DynamicMMap> 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,
if (_error->PendingError() == true)
return false;
- *OutMap = Map.UnGuard();
+ *OutMap = Map.release();
return true;
}