- /*}}}*/
-// CacheGenerator::MakeStatusCache - Construct the status cache /*{{{*/
-// ---------------------------------------------------------------------
-/* This makes sure that the status cache (the cache that has all
- index files from the sources list and all local ones) is ready
- to be mmaped. If OutMap is not zero then a MMap object representing
- the cache will be stored there. This is pretty much mandetory if you
- are using AllowMem. AllowMem lets the function be run as non-root
- where it builds the cache 'fast' into a memory buffer. */
-APT_DEPRECATED bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
+static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * const Map,
+ std::string const &FileName)
+{
+ FileFd SCacheF(FileName, FileFd::WriteAtomic);
+ if (SCacheF.IsOpen() == false || SCacheF.Failed())
+ return false;
+
+ fchmod(SCacheF.Fd(),0644);
+
+ // Write out the main data
+ if (SCacheF.Write(Map->Data(),Map->Size()) == false)
+ return _error->Error(_("IO Error saving source cache"));
+
+ // 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;
+ return true;
+}
+static bool loadBackMMapFromFile(std::unique_ptr<pkgCacheGenerator> &Gen,
+ std::unique_ptr<DynamicMMap> &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());
+ 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 Gen->Start();
+}
+bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,