- if(debug_autoremove)
- {
- std::clog << "Marking: " << pkg.FullName();
- if(!ver.end())
- std::clog << " " << ver.VerStr();
- if(!currver.end())
- std::clog << ", Curr=" << currver.VerStr();
- if(!instver.end())
- std::clog << ", Inst=" << instver.VerStr();
- std::clog << std::endl;
- }
+ // we want to ignore provides from uninteresting versions
+ auto const PV = (PkgState[PP->ID].Install()) ?
+ PkgState[PP->ID].InstVerIter(*this) : PP.CurrentVer();
+ if (unlikely(PV.end()) || PV != Prv.OwnerVer() || D.IsSatisfied(Prv) == false)
+ continue;
+
+ providers.emplace_back(PV);
+ }
+ if (providers.empty() == false)
+ {
+ // sort providers by source version so that only the latest versioned
+ // binary package of a source package is marked instead of all
+ std::sort(providers.begin(), providers.end(),
+ [](pkgCache::VerIterator const &A, pkgCache::VerIterator const &B) {
+ auto const nameret = strcmp(A.SourcePkgName(), B.SourcePkgName());
+ if (nameret != 0)
+ return nameret < 0;
+ auto const verret = A.Cache()->VS->CmpVersion(A.SourceVerStr(), B.SourceVerStr());
+ if (verret != 0)
+ return verret > 0;
+ return strcmp(A.ParentPkg().Name(), B.ParentPkg().Name()) < 0;
+ });
+ auto const prvsize = providers.size();
+ providers.erase(std::unique(providers.begin(), providers.end(),
+ [](pkgCache::VerIterator const &A, pkgCache::VerIterator const &B) {
+ return strcmp(A.SourcePkgName(), B.SourcePkgName()) == 0 &&
+ strcmp(A.SourceVerStr(), B.SourceVerStr()) != 0;
+ }), providers.end());
+ for (auto && PV: providers)
+ {
+ auto const PP = PV.ParentPkg();
+ if (debug_autoremove)
+ std::clog << "Following dep: " << APT::PrettyDep(this, D)
+ << ", provided by " << PP.FullName() << " " << PV.VerStr()
+ << " (" << providers.size() << "/" << prvsize << ")"<< std::endl;
+ MarkPackage(PP, PV, follow_recommends, follow_suggests);
+ }
+ }