summaryrefslogtreecommitdiff
path: root/apt-private/private-install.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-04-03 19:12:01 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2024-04-24 13:16:21 +0000
commite099ee946000797f4c03b8c5075ce7ebba193337 (patch)
tree817e2b6f81889dd0252ae9de976adb88a2520bee /apt-private/private-install.cc
parent7d93bcabc3f2c47c093faae7b36b7709f287cce2 (diff)
Match version constraints before saving garbage packages
We remove new garbage packages from the solution if we can as installing a new package which is at the same time considered garbage looks silly, but it could also be a new dependency of another garbage package, so we have a second round trying to save such packages. In this round we weren't considering versioned constraints on dependency relations through so even an unsatisfied old recommends could save which it shouldn't.
Diffstat (limited to 'apt-private/private-install.cc')
-rw-r--r--apt-private/private-install.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 8d1bc74f0..4f71f18c4 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -20,6 +20,7 @@
#include <apt-pkg/prettyprinters.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/upgrade.h>
+#include <apt-pkg/version.h>
#include <algorithm>
#include <cstdlib>
@@ -620,12 +621,14 @@ bool DoAutomaticRemove(CacheFile &Cache)
for (APT::PackageSet::iterator Pkg = tooMuch.begin();
Pkg != tooMuch.end(); ++Pkg)
{
- APT::PackageSet too;
- too.insert(*Pkg);
- for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
- Prv.end() == false; ++Prv)
- too.insert(Prv.ParentPkg());
- for (APT::PackageSet::const_iterator P = too.begin(); P != too.end(); ++P)
+ auto const PkgCand = Cache[Pkg].CandidateVerIter(Cache);
+ if (unlikely(PkgCand.end()))
+ continue;
+ std::vector<std::pair<pkgCache::PkgIterator, char const *>> too;
+ too.emplace_back(*Pkg, PkgCand.VerStr());
+ for (pkgCache::PrvIterator Prv = PkgCand.ProvidesList(); not Prv.end(); ++Prv)
+ too.emplace_back(Prv.ParentPkg(), Prv.ProvideVersion());
+ for (auto const &[P, PVerStr] : too)
{
for (pkgCache::DepIterator R = P.RevDependsList();
R.end() == false; ++R)
@@ -650,6 +653,11 @@ bool DoAutomaticRemove(CacheFile &Cache)
}
else // ignore dependency from a non-candidate version
continue;
+ if (R->Version != 0)
+ {
+ if (not Cache->VS().CheckDep(PVerStr, R->CompareOp, R.TargetVer()))
+ continue;
+ }
if (Debug == true)
std::clog << "Save " << APT::PrettyPkg(Cache, Pkg) << " as another installed package depends on it: " << APT::PrettyPkg(Cache, RP) << std::endl;
Cache->MarkInstall(Pkg, false, 0, false);