X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/6c55f07a5fa3612a5d59c61a17da5fe640eadc8b..63c7141275c8c5c0f6e60f5242785e50cabaf2a0:/apt-pkg/cacheset.cc diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index a4e330a0a..5e60ef54a 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -153,12 +153,8 @@ bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface * const pci, pkg continue; pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); if (Pkg.end() == true) { - if (archfound == std::string::npos) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() && Pkg.end() != true; ++a) - Pkg = Grp.FindPkg(*a); - } + if (archfound == std::string::npos) + Pkg = Grp.FindPreferredPkg(true); if (Pkg.end() == true) continue; } @@ -213,12 +209,8 @@ bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci, continue; pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); if (Pkg.end() == true) { - if (archfound == std::string::npos) { - std::vector archs = APT::Configuration::getArchitectures(); - for (std::vector::const_iterator a = archs.begin(); - a != archs.end() && Pkg.end() != true; ++a) - Pkg = Grp.FindPkg(*a); - } + if (archfound == std::string::npos) + Pkg = Grp.FindPreferredPkg(true); if (Pkg.end() == true) continue; } @@ -273,6 +265,7 @@ bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pc if (unlikely(Cache.GetPkgCache() == 0)) return false; + std::string const pkgstring = pkg; size_t const archfound = pkg.find_last_of(':'); std::string arch; if (archfound != std::string::npos) { @@ -309,7 +302,7 @@ bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pc } } - pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkg); + pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkgstring); if (Pkg.end() == true) return false; @@ -582,16 +575,126 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc return found; } /*}}}*/ +// FromDependency - versions satisfying a given dependency /*{{{*/ +bool VersionContainerInterface::FromDependency(VersionContainerInterface * const vci, + pkgCacheFile &Cache, + pkgCache::DepIterator const &D, + CacheSetHelper::VerSelector const selector, + CacheSetHelper &helper) +{ + bool found = false; + switch(selector) { + case CacheSetHelper::ALL: + { + pkgCache::PkgIterator const T = D.TargetPkg(); + for (pkgCache::VerIterator Ver = T.VersionList(); Ver.end() == false; ++Ver) + { + if (D.IsSatisfied(Ver) == true) + { + vci->insert(Ver); + found = true; + } + for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) + { + pkgCache::VerIterator const V = Prv.OwnerVer(); + if (unlikely(V.end() == true) || D.IsSatisfied(Prv) == false) + continue; + vci->insert(V); + found = true; + } + } + return found; + } + case CacheSetHelper::CANDANDINST: + { + found = FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper); + found &= FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper); + return found; + } + case CacheSetHelper::CANDIDATE: + { + pkgCache::PkgIterator const T = D.TargetPkg(); + pkgCache::VerIterator const Cand = Cache[T].CandidateVerIter(Cache); + if (Cand.end() == false && D.IsSatisfied(Cand) == true) + { + vci->insert(Cand); + found = true; + } + for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) + { + pkgCache::VerIterator const V = Prv.OwnerVer(); + pkgCache::VerIterator const Cand = Cache[Prv.OwnerPkg()].CandidateVerIter(Cache); + if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) + continue; + vci->insert(Cand); + found = true; + } + return found; + } + case CacheSetHelper::INSTALLED: + { + pkgCache::PkgIterator const T = D.TargetPkg(); + pkgCache::VerIterator const Cand = T.CurrentVer(); + if (Cand.end() == false && D.IsSatisfied(Cand) == true) + { + vci->insert(Cand); + found = true; + } + for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) + { + pkgCache::VerIterator const V = Prv.OwnerVer(); + pkgCache::VerIterator const Cand = Prv.OwnerPkg().CurrentVer(); + if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) + continue; + vci->insert(Cand); + found = true; + } + return found; + } + case CacheSetHelper::CANDINST: + return FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper) || + FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper); + case CacheSetHelper::INSTCAND: + return FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper) || + FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper); + case CacheSetHelper::NEWEST: + { + pkgCache::PkgIterator const T = D.TargetPkg(); + pkgCache::VerIterator const Cand = T.VersionList(); + if (Cand.end() == false && D.IsSatisfied(Cand) == true) + { + vci->insert(Cand); + found = true; + } + for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) + { + pkgCache::VerIterator const V = Prv.OwnerVer(); + pkgCache::VerIterator const Cand = Prv.OwnerPkg().VersionList(); + if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) + continue; + vci->insert(Cand); + found = true; + } + return found; + } + case CacheSetHelper::RELEASE: + case CacheSetHelper::VERSIONNUMBER: + // both make no sense here, so always false + return false; + } + return found; +} + /*}}}*/ // getCandidateVer - Returns the candidate version of the given package /*{{{*/ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { pkgCache::VerIterator Cand; - if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) { - if (unlikely(Cache.GetPolicy() == 0)) - return pkgCache::VerIterator(Cache); - Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); - } else { + if (Cache.IsDepCacheBuilt() == true) { Cand = Cache[Pkg].CandidateVerIter(Cache); + } else if (unlikely(Cache.GetPolicy() == nullptr)) { + return pkgCache::VerIterator(Cache); + } else { + Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); } if (Cand.end() == true) return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg); @@ -825,7 +928,8 @@ PackageContainerInterface& PackageContainerInterface::operator=(PackageContainer } PackageContainerInterface::~PackageContainerInterface() {} -PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) { } +PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) {} +PackageUniverse::PackageUniverse(pkgCacheFile * const Owner) : _cont(Owner->GetPkgCache()), d(NULL) {} PackageUniverse::~PackageUniverse() {} VersionContainerInterface::VersionContainerInterface() : d(NULL) {}