diff options
| author | Julian Andres Klode <jak@debian.org> | 2021-02-09 09:38:48 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2021-02-09 09:38:48 +0000 |
| commit | cb60beb83610783f664da0bbe1cdb7211aaba90f (patch) | |
| tree | a594f98222c256e6cec1a97c87305083823f0c91 /apt-pkg/cachefile.cc | |
| parent | 4c3383746f2974be5fdec86616f45fd85948a9aa (diff) | |
| parent | 131d0e3a261076da715102cb79275988cac810d1 (diff) | |
Merge branch 'pu/fuzzerpatches' into 'master'
Various patches uplifted from unfinished fuzzer branches
See merge request apt-team/apt!158
Diffstat (limited to 'apt-pkg/cachefile.cc')
| -rw-r--r-- | apt-pkg/cachefile.cc | 23 |
1 files changed, 19 insertions, 4 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); |
