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
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));
}
/*}}}*/
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);
std::unique_ptr<MMap> Map(new MMap(CacheF,0));
if (unlikely(Map->validData()) == false)
return false;
- pkgCache Cache(Map.get());
+ std::unique_ptr<pkgCache> CacheP(new pkgCache(Map.get()));
+ pkgCache &Cache = *CacheP.get();
if (_error->PendingError() || Map->Size() == 0)
{
if (Debug == true)
if (OutMap != 0)
*OutMap = Map.release();
+ if (OutCache != 0)
+ *OutCache = CacheP.release();
return true;
}
/*}}}*/
// 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<pkgCacheGenerator> &Gen,
{ return pkgCacheGenerator::MakeStatusCache(List, &Progress, OutMap, AllowMem); }
bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
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);
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;