+pkgCacheFile::pkgCacheFile() : d(NULL), ExternOwner(false), Map(NULL), Cache(NULL),
+ DCache(NULL), SrcList(NULL), Policy(NULL)
+{
+}
+pkgCacheFile::pkgCacheFile(pkgDepCache * const Owner) : d(NULL), ExternOwner(true),
+ Map(&Owner->GetCache().GetMap()), Cache(&Owner->GetCache()),
+ DCache(Owner), SrcList(NULL), Policy(NULL)
+{
+}
+ /*}}}*/
+// CacheFile::~CacheFile - Destructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgCacheFile::~pkgCacheFile()
+{
+ if (ExternOwner == false)
+ {
+ delete DCache;
+ delete Cache;
+ delete Map;
+ }
+ delete Policy;
+ delete SrcList;
+ if (ExternOwner == false)
+ _system->UnLock(true);
+}
+ /*}}}*/
+// CacheFile::BuildCaches - Open and build the cache files /*{{{*/
+class APT_HIDDEN ScopedErrorMerge {
+public:
+ ScopedErrorMerge() { _error->PushToStack(); }
+ ~ScopedErrorMerge() { _error->MergeWithStack(); }
+};
+
+bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
+{
+ std::unique_ptr<pkgCache> Cache;
+ std::unique_ptr<MMap> Map;
+
+ if (this->Cache != NULL)
+ return true;
+
+ ScopedErrorMerge sem;
+ if (_config->FindB("pkgCacheFile::Generate", true) == false)
+ {
+ FileFd file(_config->FindFile("Dir::Cache::pkgcache"), FileFd::ReadOnly);
+ if (file.IsOpen() == false || file.Failed())
+ return false;
+ Map.reset(new MMap(file, MMap::Public|MMap::ReadOnly));
+ if (unlikely(Map->validData() == false))
+ return false;
+ Cache.reset(new pkgCache(Map.get()));
+ if (_error->PendingError() == true)
+ return false;
+
+ this->Cache = Cache.release();
+ this->Map = Map.release();
+ return true;
+ }
+
+ if (WithLock == true)
+ if (_system->Lock() == false)
+ return false;
+
+ if (_error->PendingError() == true)
+ return false;
+
+ if (BuildSourceList(Progress) == false)
+ return false;
+
+ // Read the caches
+ MMap *TmpMap = nullptr;
+ pkgCache *TmpCache = nullptr;
+ bool Res = pkgCacheGenerator::MakeStatusCache(*SrcList,Progress,&TmpMap, &TmpCache, true);
+ Map.reset(TmpMap);
+ Cache.reset(TmpCache);
+ if (Progress != NULL)
+ Progress->Done();
+ if (Res == false)
+ return _error->Error(_("The package lists or status file could not be parsed or opened."));
+
+ /* This sux, remove it someday */
+ if (_error->PendingError() == true)
+ _error->Warning(_("You may want to run apt-get update to correct these problems"));
+
+ if (Cache == nullptr)
+ Cache.reset(new pkgCache(Map.get()));
+ if (_error->PendingError() == true)
+ return false;
+ this->Map = Map.release();
+ this->Cache = Cache.release();
+
+ return true;
+}
+ /*}}}*/
+// CacheFile::BuildSourceList - Open and build all relevant sources.list/*{{{*/