From 4175a005f98dba139208035d820bcc14de711a5a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 17 Feb 2025 21:42:29 +0100 Subject: solver3: Fix test-apt-move-and-forget-manual-sections Implement the moving of the auto bit. The whole auto-bit management is not entirely optimal yet, but this works. --- apt-pkg/solver3.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'apt-pkg/solver3.cc') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index c4fb567e1..233d7c712 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -975,6 +975,7 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) bool APT::Solver::ToDepCache(pkgDepCache &depcache) const { + FastContiguousCacheMap movedManual(cache); pkgDepCache::ActionGroup group(depcache); for (auto P = cache.PkgBegin(); not P.end(); P++) { @@ -994,10 +995,31 @@ bool APT::Solver::ToDepCache(pkgDepCache &depcache) const if (cand != P.CurrentVer()) { + bool automatic = (not reason.empty() || (depcache[P].Flags & pkgCache::Flag::Auto)) && not movedManual[P]; depcache.SetCandidateVersion(cand); - depcache.MarkInstall(P, false, 0, reason.empty() && not(depcache[P].Flags & pkgCache::Flag::Auto)); + depcache.MarkInstall(P, false, 0, not automatic); + + // Set the automatic bit for new packages or move it on upgrades to oldlibs if (not P->CurrentVer) - depcache.MarkAuto(P, not reason.empty()); + depcache.MarkAuto(P, automatic); + else if (not(depcache[P].Flags & pkgCache::Flag::Auto) && P.CurrentVer()->Section && cand->Section && not _config->SectionInSubTree("APT::Move-Autobit-Sections", P.CurrentVer().Section()) && _config->SectionInSubTree("APT::Move-Autobit-Sections", cand.Section())) + { + bool moved = false; + for (auto const &clause : (*this)[cand].clauses) + for (auto sol : clause->solutions) + { + // New installs move the auto-bit. TODO: Should we look at whether clause is the reason for installing it? + if (sol.CastPkg(cache) == P || sol.CastPkg(cache)->CurrentVer) + continue; + std::cerr << "Move manual bit from " << P.FullName() << " to " << sol.CastPkg(cache).Name() << std::endl; + movedManual[sol.CastPkg(cache)] = true; + depcache.MarkAuto(sol.CastPkg(cache), false); + moved = true; + } + if (moved) + depcache.MarkAuto(P, true); + } + } else depcache.MarkKeep(P, false, reason.empty() && not(depcache[P].Flags & pkgCache::Flag::Auto)); -- cgit v1.2.3-70-g09d2