summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-01-03 13:53:09 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2024-01-03 13:53:09 +0000
commitc82f96210eb62c92d31ded7073f4cf5371cc9485 (patch)
treeb0ba92b152c2dae076a8f0d811af287084878a89 /apt-private
parentc555d8f1ae31d1f511bf811640423231b75a8e13 (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-private')
-rw-r--r--apt-private/private-cmndline.cc5
-rw-r--r--apt-private/private-download.cc40
-rw-r--r--apt-private/private-download.h1
3 files changed, 22 insertions, 24 deletions
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index 980d00530..9e3938407 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -242,14 +242,15 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const
addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg);
addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0);
}
- else if (CmdMatches("clean", "autoclean", "auto-clean", "check", "download", "changelog") ||
+ else if (CmdMatches("clean", "autoclean", "auto-clean", "distclean", "dist-clean", "check", "download", "changelog") ||
CmdMatches("markauto", "unmarkauto")) // deprecated commands
;
else if (CmdMatches("moo"))
addArg(0, "color", "APT::Moo::Color", 0);
if (CmdMatches("install", "reinstall", "remove", "purge", "upgrade", "dist-upgrade",
- "dselect-upgrade", "autoremove", "auto-remove", "autopurge", "clean", "autoclean", "auto-clean", "check",
+ "dselect-upgrade", "autoremove", "auto-remove", "autopurge", "check",
+ "clean", "autoclean", "auto-clean", "distclean", "dist-clean",
"build-dep", "satisfy", "full-upgrade", "source"))
{
addArg('s', "simulate", "APT::Get::Simulate", 0);
diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc
index b271ec03f..d95c8ef43 100644
--- a/apt-private/private-download.cc
+++ b/apt-private/private-download.cc
@@ -303,20 +303,8 @@ bool DoChangelog(CommandLine &CmdL)
return true;
}
/*}}}*/
-
-// DoClean - Remove download archives /*{{{*/
-bool DoClean(CommandLine &)
-{
- return DoDistClean(false);
-}
- /*}}}*/
-// DoDistClean - Remove download archives and lists /*{{{*/
-bool DoDistClean(CommandLine &)
-{
- return DoDistClean(true);
-}
-// DoDistClean - the worker
-bool DoDistClean(bool ListsToo)
+// DoClean & DoDistClean - Remove download archives and/or lists /*{{{*/
+static bool CleanDownloadDirectories(bool const ListsToo)
{
std::string const archivedir = _config->FindDir("Dir::Cache::archives");
std::string const listsdir = _config->FindDir("Dir::state::lists");
@@ -325,22 +313,24 @@ bool DoDistClean(bool ListsToo)
{
std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
- std::cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< std::endl
- << "Del " << listsdir << "partial/*" << (ListsToo ? " *_{Packages,Sources}{,.diff_Index}" : "") << std::endl
- << "Del " << pkgcache << " " << srcpkgcache << std::endl;
+ std::cout << "Del " << archivedir << "* " << archivedir << "partial/*" << std::endl
+ << "Del " << listsdir << "partial/*" << std::endl;
+ if (ListsToo)
+ std::cout << "Del " << listsdir << "*_{Packages,Sources,Translation-*}{,.diff_Index}" << std::endl;
+ std::cout << "Del " << pkgcache << " " << srcpkgcache << std::endl;
return true;
}
pkgAcquire Fetcher;
- if (archivedir.empty() == false && FileExists(archivedir) == true &&
- Fetcher.GetLock(archivedir) == true)
+ if (not archivedir.empty() && FileExists(archivedir) &&
+ Fetcher.GetLock(archivedir))
{
Fetcher.Clean(archivedir);
Fetcher.Clean(archivedir + "partial/");
}
- if (listsdir.empty() == false && FileExists(listsdir) == true &&
- Fetcher.GetLock(listsdir) == true)
+ if (not listsdir.empty() && FileExists(listsdir) &&
+ Fetcher.GetLock(listsdir))
{
Fetcher.Clean(listsdir + "partial/");
if (ListsToo)
@@ -351,6 +341,14 @@ bool DoDistClean(bool ListsToo)
return true;
}
+bool DoClean(CommandLine &)
+{
+ return CleanDownloadDirectories(false);
+}
+bool DoDistClean(CommandLine &)
+{
+ return CleanDownloadDirectories(true);
+}
/*}}}*/
// DoAutoClean - Smartly remove downloaded archives /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-private/private-download.h b/apt-private/private-download.h
index 918828241..e13ade1c6 100644
--- a/apt-private/private-download.h
+++ b/apt-private/private-download.h
@@ -34,7 +34,6 @@ APT_PUBLIC bool DoChangelog(CommandLine &CmdL);
APT_PUBLIC bool DoClean(CommandLine &CmdL);
APT_PUBLIC bool DoDistClean(CommandLine &CmdL);
-bool DoDistClean(bool ListsToo);
APT_PUBLIC bool DoAutoClean(CommandLine &CmdL);
#endif