From 109fdcac9a16ffa06b06366134dcaaef7e2b3379 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 20 Mar 2025 14:30:54 +0100 Subject: solver3: Record manual flag before discovering packages When discovering packages we look at the manual flag to avoid reordering obsolete manually installed packages last. We inadvertently initialized that flag interlaced with discovering packages so if we discovered packages depending on obsolete, but manually installed, packages first, we were not aware they were manually installed and demoted them. I am struggling to come up with a test case for this as I can't get the package objects in the cache to be in the right order for the bug to trigger. LP: #2102720 --- apt-pkg/solver3.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'apt-pkg/solver3.cc') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 4030b9de1..4d988b523 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -1099,6 +1099,11 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) } } + // Clause discovery depends on the manual flag, so we need to set the manual flag first before we discover any packages + for (auto P = cache.PkgBegin(); not P.end(); P++) + if (P->CurrentVer && not(depcache[P].Flags & pkgCache::Flag::Auto) && (depcache[P].Keep() || depcache[P].Install())) + (*this)[P].flags.manual = true; + for (auto P = cache.PkgBegin(); not P.end(); P++) { if (P->VersionList == nullptr) @@ -1142,8 +1147,6 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) if (unlikely(debug >= 1)) std::cerr << "Install " << P.FullName() << " (" << (isEssential ? "E" : "") << (isAuto ? "M" : "") << (Root ? "R" : "") << ")" << "\n"; - - (*this)[P].flags.manual = not isAuto; if (not isOptional) { // Pre-empt the non-optional requests, as we don't want to queue them, we can just "unit propagate" here. -- cgit v1.2.3-70-g09d2