- // Rebuild the source and package caches
- if (SrcOk == false)
- {
- string SCacheFile = _config->FindDir("Dir::Cache::srcpkgcache");
- string ListDir = _config->FindDir("Dir::State::lists");
-
- FileFd SCacheF(SCacheFile,FileFd::WriteEmpty);
- FileFd CacheF(CacheFile,FileFd::WriteEmpty);
- DynamicMMap Map(CacheF,MMap::Public);
+ // Decide if we can write to the files..
+ string CacheFile = _config->FindFile("Dir::Cache::pkgcache");
+ string SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache");
+
+ // Decide if we can write to the cache
+ bool Writeable = false;
+ if (CacheFile.empty() == false)
+ Writeable = access(flNotFile(CacheFile).c_str(),W_OK) == 0;
+ else
+ if (SrcCacheFile.empty() == false)
+ Writeable = access(flNotFile(SrcCacheFile).c_str(),W_OK) == 0;
+
+ if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
+ return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
+
+ Progress.OverallProgress(0,1,1,_("Reading Package Lists"));
+
+ // Cache is OK, Fin.
+ if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
+ {
+ Progress.OverallProgress(1,1,1,_("Reading Package Lists"));
+ return true;
+ }
+
+ /* At this point we know we need to reconstruct the package cache,
+ begin. */
+ SPtr<FileFd> CacheF;
+ SPtr<DynamicMMap> Map;
+ if (Writeable == true && CacheFile.empty() == false)
+ {
+ unlink(CacheFile.c_str());
+ CacheF = new FileFd(CacheFile,FileFd::WriteEmpty);
+ Map = new DynamicMMap(*CacheF,MMap::Public,MapSize);