summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-12-17 15:19:53 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2021-01-04 10:54:42 +0100
commit944baec85a7496c1595242a31f6b1b37530451a5 (patch)
treec78e235efdebb13afa7e997961fcb7f07f748e63 /apt-private
parent04085f46dea9a95dd86123ac00187a63cc4ba2c0 (diff)
Automatically remove unused kernels on dist-upgrade
Kernels clutter /boot and /boot is small size, so we need to take extra care to remove kernels when possible.
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/private-install.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index af6697d7f..b110cbdc3 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -406,8 +406,15 @@ bool DoAutomaticRemove(CacheFile &Cache)
{
bool Debug = _config->FindB("Debug::pkgAutoRemove",false);
bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
+ bool doAutoRemoveKernels = _config->FindB("APT::Get::AutomaticRemove::Kernels", false);
bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
+ std::unique_ptr<APT::CacheFilter::Matcher> kernelAutoremovalMatcher;
+ if (doAutoRemoveKernels && !doAutoRemove)
+ {
+ kernelAutoremovalMatcher = APT::KernelAutoRemoveHelper::GetProtectedKernelsFilter(Cache, true);
+ }
+
pkgDepCache::ActionGroup group(*Cache);
if(Debug)
std::cout << "DoAutomaticRemove()" << std::endl;
@@ -436,7 +443,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
if(Debug)
std::cout << "We could delete " << APT::PrettyPkg(Cache, Pkg) << std::endl;
- if (doAutoRemove)
+ if (doAutoRemove || (kernelAutoremovalMatcher != nullptr && (*kernelAutoremovalMatcher)(Pkg)))
{
if(Pkg.CurrentVer() != 0 &&
Pkg->CurrentState != pkgCache::State::ConfigFiles)
@@ -692,6 +699,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg
OpTextProgress Progress(*_config);
bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0;
+ if (distUpgradeMode)
+ _config->CndSet("APT::Get::AutomaticRemove::Kernels", "true");
+
bool resolver_fail = false;
if (distUpgradeMode == true || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING)
resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress);