diff options
Diffstat (limited to 'apt-pkg/acquire.cc')
-rw-r--r-- | apt-pkg/acquire.cc | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index cdb2c5257..727880e71 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -29,6 +29,7 @@ #include <iostream> #include <memory> #include <numeric> +#include <regex> #include <sstream> #include <string> #include <tuple> @@ -825,11 +826,11 @@ pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I) return I->NextAcquire; } /*}}}*/ -// Acquire::Clean - Cleans a directory /*{{{*/ +// Acquire::CleanDir - Cleans a directory /*{{{*/ // --------------------------------------------------------------------- /* This is a bit simplistic, it looks at every file in the dir and sees - if it is part of the download set. */ -bool pkgAcquire::Clean(string Dir) + if it matches the predicate or not. */ +bool pkgAcquire::CleanDir(string Dir, std::function<bool(char const*)> const &Keep, char const * const Caller) { // non-existing directories are by definition clean… if (DirectoryExists(Dir) == false) @@ -853,22 +854,49 @@ bool pkgAcquire::Clean(string Dir) strcmp(E->d_name, "auxfiles") == 0 || strcmp(E->d_name, "lost+found") == 0 || strcmp(E->d_name, ".") == 0 || - strcmp(E->d_name, "..") == 0) + strcmp(E->d_name, "..") == 0 || + Keep(E->d_name) == true) continue; - - // Look in the get list and if not found nuke - if (std::any_of(Items.cbegin(), Items.cend(), - [&E](pkgAcquire::Item const * const I) { - return flNotDir(I->DestFile) == E->d_name; - }) == false) - { - RemoveFileAt("pkgAcquire::Clean", dirfd, E->d_name); - } + RemoveFileAt(Caller, dirfd, E->d_name); } closedir(D); return true; } /*}}}*/ +// Acquire::Clean - Cleans a directory of downloaded files /*{{{*/ +// --------------------------------------------------------------------- +/* This is a bit simplistic, it looks at every file in the dir and sees + if it is part of the download set. */ +bool pkgAcquire::Clean(string Dir) +{ + return CleanDir( + Dir, + // Look in the get list and if found then keep + [this](char const *FName) { + return std::any_of(Items.cbegin(), Items.cend(), + [FName](pkgAcquire::Item const * const I) { + return flNotDir(I->DestFile) == FName; + }); + }, + "pkgAcquire::Clean" + ); +} + /*}}}*/ +// Acquire::CleanLists - Cleans a directory of list files /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgAcquire::CleanLists(string Dir) +{ + return CleanDir( + Dir, + [](char const *FName) noexcept { + static const std::regex KeepPattern(".*_(Release|Release.gpg|InRelease)"); + return std::regex_match(FName, KeepPattern); + }, + "pkgAcquire::CleanLists" + ); +} + /*}}}*/ // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/ // --------------------------------------------------------------------- /* This is the total number of bytes needed */ |