summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-06-10 16:09:19 +0200
committerJulian Andres Klode <jak@debian.org>2025-06-10 16:27:36 +0200
commitb99ec5f1d80962e39e9debb05f1a7c7840e7d97c (patch)
tree9e308b4938dd804cd91d435b1662099714892915
parent060f4e274f08ea338158606fc81b451924a293d0 (diff)
solver3: Filter installed Recommends
When inspecting Recommends of installed packages, filter them to the installed packages only, as we want to avoid switching between alternatives of recommended packages.
-rw-r--r--apt-pkg/solver3.cc10
-rwxr-xr-xtest/integration/test-solver3-break-recommends29
2 files changed, 39 insertions, 0 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index 052142658..c2877946c 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -964,6 +964,16 @@ APT::Solver::Clause APT::Solver::TranslateOrGroup(pkgCache::DepIterator start, p
std::cerr << "Promoting new clause to hard dependency: " << clause.toString(cache) << std::endl;
clause.optional = false;
}
+ else if (not existing.end() && importantToKeep(start) && satisfied)
+ {
+ if (unlikely(debug >= 3))
+ std::cerr << "Restricting existing Recommends to installed packages: " << clause.toString(cache, true) << std::endl;
+ // Erase the non-installed solutions. We will process this last and try to keep the previously installed
+ // "best" solution installed.
+ clause.solutions.erase(std::remove_if(clause.solutions.begin(), clause.solutions.end(), [this](auto var)
+ { return var.CastPkg(cache)->CurrentVer == nullptr; }),
+ clause.solutions.end());
+ }
}
return clause;
diff --git a/test/integration/test-solver3-break-recommends b/test/integration/test-solver3-break-recommends
new file mode 100755
index 000000000..88051f5de
--- /dev/null
+++ b/test/integration/test-solver3-break-recommends
@@ -0,0 +1,29 @@
+#!/bin/sh
+set -e
+
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
+setupenvironment
+configarchitecture 'amd64'
+
+insertpackage 'installed' 'root' 'all' '1' 'Recommends: a | b'
+insertpackage 'installed,unstable' 'a' 'all' '1'
+insertpackage 'unstable' 'b' 'all' '1'
+
+setupaptarchive
+
+msgmsg "b should not be installed"
+
+testsuccessequal "Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ a
+0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv a [1]" aptget remove a -s
+
+testsuccessequal "Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ a
+0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv a [1]" apt remove a -s