summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefile.cc23
-rw-r--r--apt-pkg/pkgcachegen.cc11
2 files changed, 29 insertions, 5 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index 8b86fa3e4..5355994d3 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -27,10 +27,13 @@
#include <apt-pkg/progress.h>
#include <apt-pkg/sourcelist.h>
+#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <apti18n.h>
@@ -288,15 +291,27 @@ bool pkgCacheFile::AddIndexFile(pkgIndexFile * const File) /*{{{*/
// CacheFile::RemoveCaches - remove all cache files from disk /*{{{*/
// ---------------------------------------------------------------------
/* */
+static void SetCacheStartBeforeRemovingCache(std::string const &cache)
+{
+ if (cache.empty())
+ return;
+ auto const CacheStart = _config->FindI("APT::Cache-Start", 0);
+ constexpr auto CacheStartDefault = 24 * 1024 * 1024;
+ struct stat Buf;
+ if (stat(cache.c_str(), &Buf) == 0 && (Buf.st_mode & S_IFREG) != 0)
+ {
+ RemoveFile("RemoveCaches", cache);
+ if (CacheStart == 0 && std::numeric_limits<decltype(CacheStart)>::max() >= Buf.st_size && Buf.st_size > CacheStartDefault)
+ _config->Set("APT::Cache-Start", Buf.st_size);
+ }
+}
void pkgCacheFile::RemoveCaches()
{
std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
+ SetCacheStartBeforeRemovingCache(pkgcache);
std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
+ SetCacheStartBeforeRemovingCache(srcpkgcache);
- if (pkgcache.empty() == false && RealFileExists(pkgcache) == true)
- RemoveFile("RemoveCaches", pkgcache);
- if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
- RemoveFile("RemoveCaches", srcpkgcache);
if (pkgcache.empty() == false)
{
std::string cachedir = flNotFile(pkgcache);
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 6f2e3268c..b4fd0641e 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -37,6 +37,8 @@
#include <apti18n.h>
/*}}}*/
+constexpr auto APT_CACHE_START_DEFAULT = 24 * 1024 * 1024;
+
template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>;
typedef std::vector<pkgIndexFile *>::iterator FileIterator;
template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
@@ -1383,6 +1385,13 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
return false;
}
+ if (_config->FindI("APT::Cache-Start", 0) == 0)
+ {
+ auto const size = CacheFile.FileSize();
+ if (std::numeric_limits<int>::max() >= size && size > APT_CACHE_START_DEFAULT)
+ _config->Set("APT::Cache-Start", size);
+ }
+
if (List.GetLastModifiedTime() > CacheFile.ModificationTime())
{
if (Debug == true)
@@ -1591,7 +1600,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
where it builds the cache 'fast' into a memory buffer. */
static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags)
{
- map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", 24*1024*1024);
+ map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", APT_CACHE_START_DEFAULT);
map_filesize_t const MapGrow = _config->FindI("APT::Cache-Grow", 1*1024*1024);
map_filesize_t const MapLimit = _config->FindI("APT::Cache-Limit", 0);
Flags |= MMap::Moveable;