merged from debian-sid
[ntk/apt.git] / apt-pkg / pkgcachegen.cc
index 9820fde..efd764b 100644 (file)
@@ -105,6 +105,9 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
    if (oldMap == newMap)
       return;
 
+   if (_config->FindB("Debug::pkgCacheGen", false))
+      std::clog << "Remaping from " << oldMap << " to " << newMap << std::endl;
+
    Cache.ReMap(false);
 
    CurrentFile += (pkgCache::PackageFile*) newMap - (pkgCache::PackageFile*) oldMap;
@@ -684,7 +687,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
                                   string const &Version,
                                   unsigned int const &Op,
                                   unsigned int const &Type,
-                                  map_ptrloc *OldDepLast)
+                                  map_ptrloc* &OldDepLast)
 {
    void const * const oldMap = Map.Data();
    // Get a structure
@@ -915,8 +918,11 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
 /* This just verifies that each file in the list of index files exists,
    has matching attributes with the cache and the cache does not have
    any extra files. */
-static bool CheckValidity(const string &CacheFile, FileIterator Start, 
-                          FileIterator End,MMap **OutMap = 0)
+static bool CheckValidity(const string &CacheFile, 
+                          pkgSourceList &List,
+                          FileIterator Start, 
+                          FileIterator End,
+                          MMap **OutMap = 0)
 {
    bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
    // No file, certainly invalid
@@ -927,6 +933,13 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start,
       return false;
    }
 
+   if (List.GetLastModifiedTime() < GetModificationTime(CacheFile))
+   {
+      if (Debug == true)
+        std::clog << "sources.list is newer than the cache" << std::endl;
+      return false;
+   }
+
    // Map it
    FileFd CacheF(CacheFile,FileFd::ReadOnly);
    SPtr<MMap> Map = new MMap(CacheF,0);
@@ -1152,7 +1165,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
       Progress->OverallProgress(0,1,1,_("Reading package lists"));
 
    // Cache is OK, Fin.
-   if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
+   if (CheckValidity(CacheFile, List, Files.begin(),Files.end(),OutMap) == true)
    {
       if (Progress != NULL)
         Progress->OverallProgress(1,1,1,_("Reading package lists"));
@@ -1169,16 +1182,32 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    SPtr<DynamicMMap> Map;
    if (Writeable == true && CacheFile.empty() == false)
    {
+      _error->PushToStack();
       unlink(CacheFile.c_str());
       CacheF = new FileFd(CacheFile,FileFd::WriteAtomic);
       fchmod(CacheF->Fd(),0644);
       Map = CreateDynamicMMap(CacheF, MMap::Public);
       if (_error->PendingError() == true)
-        return false;
-      if (Debug == true)
+      {
+        delete CacheF.UnGuard();
+        delete Map.UnGuard();
+        if (Debug == true)
+           std::clog << "Open filebased MMap FAILED" << std::endl;
+        Writeable = false;
+        if (AllowMem == false)
+        {
+           _error->MergeWithStack();
+           return false;
+        }
+        _error->RevertToStack();
+      }
+      else if (Debug == true)
+      {
+        _error->MergeWithStack();
         std::clog << "Open filebased MMap" << std::endl;
+      }
    }
-   else
+   if (Writeable == false || CacheFile.empty() == true)
    {
       // Just build it in memory..
       Map = CreateDynamicMMap(NULL);
@@ -1189,7 +1218,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    // Lets try the source cache.
    unsigned long CurrentSize = 0;
    unsigned long TotalSize = 0;
-   if (CheckValidity(SrcCacheFile,Files.begin(),
+   if (CheckValidity(SrcCacheFile, List, Files.begin(),
                     Files.begin()+EndOfSource) == true)
    {
       if (Debug == true)