pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
Map(*pMap), Cache(pMap,false), Progress(Prog),
CurrentRlsFile(NULL), CurrentFile(NULL), d(NULL)
+{
+}
+bool pkgCacheGenerator::Start()
{
if (Map.Size() == 0)
{
bool const newError = _error->PendingError();
_error->MergeWithStack();
if (newError)
- return;
+ return false;
+ if (Map.Size() <= 0)
+ return false;
Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
// make room for the hashtables for packages and groups
if (Map.RawAllocate(2 * (Cache.HeaderP->GetHashTableSize() * sizeof(map_pointer_t))) == 0)
- return;
+ return false;
map_stringitem_t const idxVerSysName = WriteStringInMap(_system->VS->Label);
if (unlikely(idxVerSysName == 0))
- return;
- Cache.HeaderP->VerSysName = idxVerSysName;
+ return false;
map_stringitem_t const idxArchitecture = StoreString(MIXED, _config->Find("APT::Architecture"));
if (unlikely(idxArchitecture == 0))
- return;
- Cache.HeaderP->Architecture = idxArchitecture;
+ return false;
+ map_stringitem_t idxArchitectures;
std::vector<std::string> archs = APT::Configuration::getArchitectures();
if (archs.size() > 1)
std::string list = *a;
for (++a; a != archs.end(); ++a)
list.append(",").append(*a);
- map_stringitem_t const idxArchitectures = WriteStringInMap(list);
+ idxArchitectures = WriteStringInMap(list);
if (unlikely(idxArchitectures == 0))
- return;
- Cache.HeaderP->SetArchitectures(idxArchitectures);
+ return false;
}
else
- Cache.HeaderP->SetArchitectures(idxArchitecture);
+ idxArchitectures = idxArchitecture;
+
+ Cache.HeaderP = (pkgCache::Header *)Map.Data();
+ Cache.HeaderP->VerSysName = idxVerSysName;
+ Cache.HeaderP->Architecture = idxArchitecture;
+ Cache.HeaderP->SetArchitectures(idxArchitectures);
// Calculate the hash for the empty map, so ReMap does not fail
Cache.HeaderP->CacheFileSize = Cache.CacheHash();
Cache.ReMap();
Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
if (Cache.VS != _system->VS)
- {
- _error->Error(_("Cache has an incompatible versioning system"));
- return;
- }
+ return _error->Error(_("Cache has an incompatible versioning system"));
}
Cache.HeaderP->Dirty = true;
Map.Sync(0,sizeof(pkgCache::Header));
+ return true;
}
/*}}}*/
// CacheGenerator::~pkgCacheGenerator - Destructor /*{{{*/
}
/*}}}*/
void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap, size_t oldSize) {/*{{{*/
+ // Prevent multiple remaps of the same iterator. If seen.insert(iterator)
+ // returns (something, true) the iterator was not yet seen and we can
+ // remap it.
+ std::unordered_set<void *> seen;
if (oldMap == newMap)
return;
for (std::vector<pkgCache::GrpIterator*>::const_iterator i = Dynamic<pkgCache::GrpIterator>::toReMap.begin();
i != Dynamic<pkgCache::GrpIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::PkgIterator*>::const_iterator i = Dynamic<pkgCache::PkgIterator>::toReMap.begin();
i != Dynamic<pkgCache::PkgIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::VerIterator*>::const_iterator i = Dynamic<pkgCache::VerIterator>::toReMap.begin();
i != Dynamic<pkgCache::VerIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::DepIterator*>::const_iterator i = Dynamic<pkgCache::DepIterator>::toReMap.begin();
i != Dynamic<pkgCache::DepIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::DescIterator*>::const_iterator i = Dynamic<pkgCache::DescIterator>::toReMap.begin();
i != Dynamic<pkgCache::DescIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::PrvIterator*>::const_iterator i = Dynamic<pkgCache::PrvIterator>::toReMap.begin();
i != Dynamic<pkgCache::PrvIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::PkgFileIterator*>::const_iterator i = Dynamic<pkgCache::PkgFileIterator>::toReMap.begin();
i != Dynamic<pkgCache::PkgFileIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (std::vector<pkgCache::RlsFileIterator*>::const_iterator i = Dynamic<pkgCache::RlsFileIterator>::toReMap.begin();
i != Dynamic<pkgCache::RlsFileIterator>::toReMap.end(); ++i)
- (*i)->ReMap(oldMap, newMap);
+ if (std::get<1>(seen.insert(*i)) == true)
+ (*i)->ReMap(oldMap, newMap);
for (APT::StringView* ViewP : Dynamic<APT::StringView>::toReMap) {
+ if (std::get<1>(seen.insert(ViewP)) == false)
+ continue;
// Ignore views outside of the cache.
if (ViewP->data() < static_cast<const char*>(oldMap)
|| ViewP->data() > static_cast<const char*>(oldMap) + oldSize)
if (Res > 0)
break;
// Versionstrings are equal - is hash also equal?
- if (Res == 0 && List.SameVersion(Hash, Ver) == true)
- break;
+ if (Res == 0)
+ {
+ if (List.SameVersion(Hash, Ver) == true)
+ break;
+ // sort (volatile) sources above not-sources like the status file
+ if ((CurrentFile->Flags & pkgCache::Flag::NotSource) == 0)
+ {
+ auto VF = Ver.FileList();
+ for (; VF.end() == false; ++VF)
+ if (VF.File().Flagged(pkgCache::Flag::NotSource) == false)
+ break;
+ if (VF.end() == true)
+ break;
+ }
+ }
// proceed with the next till we have either the right
// or we found another version (which will be lower)
}
if (CacheF.Read((unsigned char *)Map->Data() + alloc, CacheF.Size()) == false)
return false;
Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
- return true;
+ return Gen->Start();
}
bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
MMap **OutMap, bool AllowMem)
if (Debug == true)
std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
+ if (Gen->Start() == false)
+ return false;
TotalSize += ComputeSize(&List, Files.begin(),Files.end());
if (BuildCache(*Gen, Progress, CurrentSize, TotalSize, &List,
if (Progress != NULL)
Progress->OverallProgress(0,1,1,_("Reading package lists"));
pkgCacheGenerator Gen(Map.get(),Progress);
- if (_error->PendingError() == true)
+ if (Gen.Start() == false || _error->PendingError() == true)
return false;
if (BuildCache(Gen,Progress,CurrentSize,TotalSize, NULL,
Files.begin(), Files.end()) == false)