summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-05-24 13:42:11 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2024-05-24 13:43:56 +0200
commit67a8a6470ddb8a603db02c5fab84aa225dc00f8d (patch)
treebf3dd748f531b5be164ae8bbe4ac018383793db6
parent4fc6affafafda1aee4cee86294ce7a2b799e2799 (diff)
solver3: Implement APT::Solver::RemoveManual to allow removing manual packages
This is mostly going to be useful for the test suite for now, implement a function there to set it up so we can use it to improve test suite correctness.
-rw-r--r--apt-pkg/solver3.cc7
-rw-r--r--doc/examples/configure-index1
-rw-r--r--test/integration/framework3
3 files changed, 9 insertions, 2 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index d43bd5b33..ab66c9501 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -853,6 +853,7 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache)
bool KeepAuto = not _config->FindB("APT::Get::AutomaticRemove");
bool AllowRemove = _config->FindB("APT::Solver::Remove", true);
bool AllowInstall = _config->FindB("APT::Solver::Install", true);
+ bool AllowRemoveManual = _config->FindB("APT::Solver::RemoveManual", false);
DefaultRootSetFunc2 rootSet(&cache);
for (auto P = cache.PkgBegin(); not P.end(); P++)
@@ -863,6 +864,8 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache)
auto state = depcache[P];
auto maybeInstall = state.Install() || (state.Keep() && P->CurrentVer);
auto reject = state.Delete() || (depcache[P].Keep() && not P->CurrentVer && depcache[P].Protect());
+ auto isAuto = (depcache[P].Flags & pkgCache::Flag::Auto);
+ auto isOptional = isAuto || (AllowRemoveManual && not depcache[P].Protect());
if (P->SelectedState == pkgCache::State::Hold && not state.Protect())
{
if (unlikely(debug >= 1))
@@ -884,14 +887,14 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache)
if (depcache[P].Keep() ? not Install(P, {}) : not Install(depcache.GetCandidateVersion(P), {}))
return false;
}
- else if (maybeInstall && not(depcache[P].Flags & pkgCache::Flag::Auto))
+ else if (maybeInstall && not isOptional)
{
if (unlikely(debug >= 1))
std::cerr << "MANUAL " << P.FullName() << "\n";
if (depcache[P].Keep() ? not Install(P, {}) : not Install(depcache.GetCandidateVersion(P), {}))
return false;
}
- else if (maybeInstall && (KeepAuto || rootSet.InRootSet(P)) && (depcache[P].Flags & pkgCache::Flag::Auto))
+ else if (maybeInstall && isOptional && (KeepAuto || rootSet.InRootSet(P) || not isAuto))
{
auto Upgrade = depcache.GetCandidateVersion(P) != P.CurrentVer();
if (unlikely(debug >= 1))
diff --git a/doc/examples/configure-index b/doc/examples/configure-index
index c27a8f862..6bcf8e354 100644
--- a/doc/examples/configure-index
+++ b/doc/examples/configure-index
@@ -724,6 +724,7 @@ apt::solver::strict-pinning "<BOOL>";
apt::solver::enqueue-common-dependencies "<BOOL>";
apt::solver::upgrade "<BOOL>";
apt::solver::remove "<BOOL>";
+apt::solver::removemanual "<BOOL>";
apt::solver::install "<BOOL>";
apt::keep-downloaded-packages "<BOOL>";
apt::solver "<STRING>";
diff --git a/test/integration/framework b/test/integration/framework
index d2ab0d1cd..ecf5d8703 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -585,6 +585,9 @@ EOF
# prefer our apt binaries over the system apt binaries
export PATH="${APTCMDLINEBINDIR}:${PATH}:/usr/sbin:/sbin"
}
+allowremovemanual() {
+ echo 'APT::Solver::RemoveManual "true";' >> ${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/allow-remove-manual.conf
+}
getarchitecture() {
if [ "$1" = "native" -o -z "$1" ]; then