diff options
| author | David Kalnischkies <david@kalnischkies.de> | 2024-01-03 13:53:09 +0000 |
|---|---|---|
| committer | David Kalnischkies <david@kalnischkies.de> | 2024-01-03 13:53:09 +0000 |
| commit | c82f96210eb62c92d31ded7073f4cf5371cc9485 (patch) | |
| tree | b0ba92b152c2dae076a8f0d811af287084878a89 /apt-pkg/acquire.cc | |
| parent | c555d8f1ae31d1f511bf811640423231b75a8e13 (diff) | |
Improve and test distclean implementation
The implementation as-is as various smaller/esoteric bugs and
inconsistencies like apt-get not supporting them, the option -s
being supported in code but not accepted on the command line,
the regex not escaping the dot before the file extension and
exposing more implementation details to public headers than we
actually need.
Also comes with a small test case to ensure it actually works.
References: bd7c126e3fb1b94e76e0e632c657cea854586844
Diffstat (limited to 'apt-pkg/acquire.cc')
| -rw-r--r-- | apt-pkg/acquire.cc | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 727880e71..1cb55bf14 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -826,11 +826,11 @@ pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I) return I->NextAcquire; } /*}}}*/ -// Acquire::CleanDir - Cleans a directory /*{{{*/ +// CleanDir - Cleans a directory /*{{{*/ // --------------------------------------------------------------------- /* This is a bit simplistic, it looks at every file in the dir and sees if it matches the predicate or not. */ -bool pkgAcquire::CleanDir(string Dir, std::function<bool(char const*)> const &Keep, char const * const Caller) +static bool CleanDir(std::string const &Dir, std::function<bool(std::string_view)> const &Keep, char const * const Caller) { // non-existing directories are by definition clean… if (DirectoryExists(Dir) == false) @@ -855,7 +855,7 @@ bool pkgAcquire::CleanDir(string Dir, std::function<bool(char const*)> const &Ke strcmp(E->d_name, "lost+found") == 0 || strcmp(E->d_name, ".") == 0 || strcmp(E->d_name, "..") == 0 || - Keep(E->d_name) == true) + Keep(E->d_name)) continue; RemoveFileAt(Caller, dirfd, E->d_name); } @@ -867,12 +867,12 @@ bool pkgAcquire::CleanDir(string Dir, std::function<bool(char const*)> const &Ke // --------------------------------------------------------------------- /* 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) +bool pkgAcquire::Clean(std::string Dir) { return CleanDir( Dir, // Look in the get list and if found then keep - [this](char const *FName) { + [this](std::string_view const FName) { return std::any_of(Items.cbegin(), Items.cend(), [FName](pkgAcquire::Item const * const I) { return flNotDir(I->DestFile) == FName; @@ -882,21 +882,19 @@ bool pkgAcquire::Clean(string Dir) ); } /*}}}*/ -// Acquire::CleanLists - Cleans a directory of list files /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool pkgAcquire::CleanLists(string Dir) +// Acquire::CleanLists - Cleans a directory of list files /*{{{*/ +bool pkgAcquire::CleanLists(std::string const &Dir) { + std::regex const KeepPattern(".*_(Release|Release\\.gpg|InRelease)"); return CleanDir( Dir, - [](char const *FName) noexcept { - static const std::regex KeepPattern(".*_(Release|Release.gpg|InRelease)"); - return std::regex_match(FName, KeepPattern); + [&KeepPattern](std::string_view const FName) noexcept { + return std::regex_match(FName.begin(), FName.end(), KeepPattern); }, "pkgAcquire::CleanLists" ); } - /*}}}*/ + /*}}}*/ // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/ // --------------------------------------------------------------------- /* This is the total number of bytes needed */ |
