X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/8daf68e366fa9fa2794ae667f51562663856237c..e93b4028825648bb29074a1422287e2cb435b0de:/apt-pkg/algorithms.cc diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index db1ebd7e3..6d982c551 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -19,19 +19,16 @@ #include #include #include -#include -#include -#include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#include #include -#include #include -#include #include /*}}}*/ @@ -44,7 +41,7 @@ pkgProblemResolver *pkgProblemResolver::This = 0; /* The legacy translations here of input Pkg iterators is obsolete, this is not necessary since the pkgCaches are fully shared now. */ pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache), - iPolicy(Cache), + d(NULL), iPolicy(Cache), Sim(&Cache->GetCache(),&iPolicy), group(Sim) { @@ -446,31 +443,39 @@ void pkgProblemResolver::MakeScores() || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) Score += PrioEssentials; - // We transform the priority - if (Cache[I].InstVerIter(Cache)->Priority <= 5) - Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority]; - + pkgCache::VerIterator const InstVer = Cache[I].InstVerIter(Cache); + // We apply priorities only to downloadable packages, all others are prio:extra + // as an obsolete prio:standard package can't be that standard anymore… + if (InstVer->Priority <= pkgCache::State::Extra && InstVer.Downloadable() == true) + Score += PrioMap[InstVer->Priority]; + else + Score += PrioMap[pkgCache::State::Extra]; + /* This helps to fix oddball problems with conflicting packages - on the same level. We enhance the score of installed packages - if those are not obsolete - */ + on the same level. We enhance the score of installed packages + if those are not obsolete */ if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable()) Score += PrioInstalledAndNotObsolete; - } - - // Now that we have the base scores we go and propagate dependencies - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) - { - if (Cache[I].InstallVer == 0) - continue; - for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D) - Scores[D.TargetPkg()->ID] += DepMap[D->Type]; + // propagate score points along dependencies + for (pkgCache::DepIterator D = InstVer.DependsList(); D.end() == false; ++D) + { + if (DepMap[D->Type] == 0) + continue; + pkgCache::PkgIterator const T = D.TargetPkg(); + if (D->Version != 0) + { + pkgCache::VerIterator const IV = Cache[T].InstVerIter(Cache); + if (IV.end() == true || D.IsSatisfied(IV) == false) + continue; + } + Scores[T->ID] += DepMap[D->Type]; + } } // Copy the scores to advoid additive looping - SPtrArray OldScores = new int[Size]; - memcpy(OldScores,Scores,sizeof(*Scores)*Size); + std::unique_ptr OldScores(new int[Size]); + memcpy(OldScores.get(),Scores,sizeof(*Scores)*Size); /* Now we cause 1 level of dependency inheritance, that is we add the score of the packages that depend on the target Package. This @@ -631,15 +636,11 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) } /*}}}*/ // ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool pkgProblemResolver::Resolve(bool BrokenFix) +bool pkgProblemResolver::Resolve(bool BrokenFix, OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, false, false, false, Progress); return ResolveInternal(BrokenFix); } /*}}}*/ @@ -699,17 +700,17 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) operates from highest score to lowest. This prevents problems when high score packages cause the removal of lower score packages that would cause the removal of even lower score packages. */ - SPtrArray PList = new pkgCache::Package *[Size]; - pkgCache::Package **PEnd = PList; + std::unique_ptr PList(new pkgCache::Package *[Size]); + pkgCache::Package **PEnd = PList.get(); for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; - qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); + qsort(PList.get(),PEnd - PList.get(),sizeof(PList[0]),&ScoreSort); if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true) { clog << "Show Scores" << endl; - for (pkgCache::Package **K = PList; K != PEnd; K++) + for (pkgCache::Package **K = PList.get(); K != PEnd; K++) if (Scores[(*K)->ID] != 0) { pkgCache::PkgIterator Pkg(Cache,*K); @@ -731,7 +732,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) for (int Counter = 0; Counter != 10 && Change == true; Counter++) { Change = false; - for (pkgCache::Package **K = PList; K != PEnd; K++) + for (pkgCache::Package **K = PList.get(); K != PEnd; K++) { pkgCache::PkgIterator I(Cache,*K); @@ -842,8 +843,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) /* Look across the version list. If there are no possible targets then we keep the package and bail. This is necessary if a package has a dep on another package that can't be found */ - SPtrArray VList = Start.AllTargets(); - if (*VList == 0 && (Flags[I->ID] & Protected) != Protected && + std::unique_ptr VList(Start.AllTargets()); + if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected && Start.IsNegative() == false && Cache[I].NowBroken() == false) { @@ -860,7 +861,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) } bool Done = false; - for (pkgCache::Version **V = VList; *V != 0; V++) + for (pkgCache::Version **V = VList.get(); *V != 0; V++) { pkgCache::VerIterator Ver(Cache,*V); pkgCache::PkgIterator Pkg = Ver.ParentPkg(); @@ -880,8 +881,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) } if (Debug == true) - clog << " Considering " << Pkg.FullName(false) << ' ' << (int)Scores[Pkg->ID] << - " as a solution to " << I.FullName(false) << ' ' << (int)Scores[I->ID] << endl; + clog << " Considering " << Pkg.FullName(false) << ' ' << Scores[Pkg->ID] << + " as a solution to " << I.FullName(false) << ' ' << Scores[I->ID] << endl; /* Try to fix the package under consideration rather than fiddle with the VList package */ @@ -1133,13 +1134,11 @@ bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I) /* This is the work horse of the soft upgrade routine. It is very gental in that it does not install or remove any packages. It is assumed that the system was non-broken previously. */ -bool pkgProblemResolver::ResolveByKeep() +bool pkgProblemResolver::ResolveByKeep(OpProgress * const Progress) { std::string const solver = _config->Find("APT::Solver", "internal"); - if (solver != "internal") { - OpTextProgress Prog(*_config); - return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, &Prog); - } + if (solver != "internal") + return EDSP::ResolveExternal(solver.c_str(), Cache, true, false, false, Progress); return ResolveByKeepInternal(); } /*}}}*/ @@ -1232,8 +1231,8 @@ bool pkgProblemResolver::ResolveByKeepInternal() clog << "Package " << I.FullName(false) << " " << Start << endl; // Look at all the possible provides on this package - SPtrArray VList = Start.AllTargets(); - for (pkgCache::Version **V = VList; *V != 0; V++) + std::unique_ptr VList(Start.AllTargets()); + for (pkgCache::Version **V = VList.get(); *V != 0; V++) { pkgCache::VerIterator Ver(Cache,*V); pkgCache::PkgIterator Pkg = Ver.ParentPkg();