]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cachefile.cc
search: Handle packages without description
[apt.git] / apt-pkg / cachefile.cc
index 1c9bc694b68e1e899afbbf4301f26687fe17657b..92a3b201bb8524f9f3e4f0252cd8ef70f7928387 100644 (file)
@@ -80,6 +80,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
       if (file.IsOpen() == false || file.Failed())
         return false;
       Map = new MMap(file, MMap::Public|MMap::ReadOnly);
+      if (unlikely(Map->validData() == false))
+        return false;
       Cache = new pkgCache(Map);
       return _error->PendingError() == false;
    }
@@ -94,7 +96,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
    BuildSourceList(Progress);
 
    // Read the caches
-   bool Res = pkgCacheGenerator::MakeStatusCache(*SrcList,Progress,&Map, true);
+   Cache = nullptr;
+   bool Res = pkgCacheGenerator::MakeStatusCache(*SrcList,Progress,&Map, &Cache, true);
    if (Progress != NULL)
       Progress->Done();
    if (Res == false)
@@ -104,7 +107,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
    if (_error->PendingError() == true)
       _error->Warning(_("You may want to run apt-get update to correct these problems"));
 
-   Cache = new pkgCache(Map);
+   if (Cache == nullptr)
+      Cache = new pkgCache(Map);
    if (_error->PendingError() == true)
       return false;
    return true;
@@ -191,9 +195,9 @@ void pkgCacheFile::RemoveCaches()
    std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
 
    if (pkgcache.empty() == false && RealFileExists(pkgcache) == true)
-      unlink(pkgcache.c_str());
+      RemoveFile("RemoveCaches", pkgcache);
    if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
-      unlink(srcpkgcache.c_str());
+      RemoveFile("RemoveCaches", srcpkgcache);
    if (pkgcache.empty() == false)
    {
       std::string cachedir = flNotFile(pkgcache);
@@ -207,7 +211,7 @@ void pkgCacheFile::RemoveCaches()
            std::string nuke = flNotDir(*file);
            if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
               continue;
-           unlink(file->c_str());
+           RemoveFile("RemoveCaches", *file);
         }
       }
    }
@@ -226,7 +230,7 @@ void pkgCacheFile::RemoveCaches()
       std::string nuke = flNotDir(*file);
       if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0)
         continue;
-      unlink(file->c_str());
+      RemoveFile("RemoveCaches", *file);
    }
 }
                                                                        /*}}}*/