summaryrefslogtreecommitdiff
path: root/apt-pkg/algorithms.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/algorithms.cc')
-rw-r--r--apt-pkg/algorithms.cc161
1 files changed, 117 insertions, 44 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index 2dae4258a..40368c91f 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -14,18 +14,23 @@
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
+#include <config.h>
+
#include <apt-pkg/algorithms.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/version.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/acquire-item.h>
-
-#include <apti18n.h>
+#include <apt-pkg/edsp.h>
+
#include <sys/types.h>
#include <cstdlib>
#include <algorithm>
#include <iostream>
+#include <stdio.h>
+
+#include <apti18n.h>
/*}}}*/
using namespace std;
@@ -91,7 +96,7 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
Sim.MarkInstall(Pkg,false);
// Look for broken conflicts+predepends.
- for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
+ for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I)
{
if (Sim[I].InstallVer == 0)
continue;
@@ -140,7 +145,7 @@ bool pkgSimulate::Configure(PkgIterator iPkg)
Sim.Update();
// Print out each package and the failed dependencies
- for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; D++)
+ for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; ++D)
{
if (Sim.IsImportantDep(D) == false ||
(Sim[D] & pkgDepCache::DepInstall) != 0)
@@ -204,7 +209,7 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge)
void pkgSimulate::ShortBreaks()
{
cout << " [";
- for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
+ for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I)
{
if (Sim[I].InstBroken() == true)
{
@@ -226,7 +231,7 @@ bool pkgApplyStatus(pkgDepCache &Cache)
{
pkgDepCache::ActionGroup group(Cache);
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (I->VersionList == 0)
continue;
@@ -295,13 +300,13 @@ bool pkgFixBroken(pkgDepCache &Cache)
pkgDepCache::ActionGroup group(Cache);
// Auto upgrade all broken packages
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (Cache[I].NowBroken() == true)
Cache.MarkInstall(I, true, 0, false);
/* Fix packages that are in a NeedArchive state but don't have a
downloadable install version */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (I.State() != pkgCache::PkgIterator::NeedsUnpack ||
Cache[I].Delete() == true)
@@ -327,6 +332,12 @@ bool pkgFixBroken(pkgDepCache &Cache)
*/
bool pkgDistUpgrade(pkgDepCache &Cache)
{
+ std::string const solver = _config->Find("APT::Solver", "internal");
+ if (solver != "internal") {
+ OpTextProgress Prog(*_config);
+ return EDSP::ResolveExternal(solver.c_str(), Cache, false, true, false, &Prog);
+ }
+
pkgDepCache::ActionGroup group(Cache);
/* Upgrade all installed packages first without autoinst to help the resolver
@@ -338,19 +349,19 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
/* Auto upgrade all installed packages, this provides the basis
for the installation */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (I->CurrentVer != 0)
Cache.MarkInstall(I, true, 0, false);
/* Now, auto upgrade all essential packages - this ensures that
the essential packages are present and working */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
Cache.MarkInstall(I, true, 0, false);
/* We do it again over all previously installed packages to force
conflict resolution on them all. */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
if (I->CurrentVer != 0)
Cache.MarkInstall(I, false, 0, false);
@@ -359,7 +370,7 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
// Hold back held packages.
if (_config->FindB("APT::Ignore-Hold",false) == false)
{
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (I->SelectedState == pkgCache::State::Hold)
{
@@ -379,6 +390,12 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
to install packages not marked for install */
bool pkgAllUpgrade(pkgDepCache &Cache)
{
+ 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);
+ }
+
pkgDepCache::ActionGroup group(Cache);
pkgProblemResolver Fix(&Cache);
@@ -387,7 +404,7 @@ bool pkgAllUpgrade(pkgDepCache &Cache)
return false;
// Upgrade all installed packages
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (Cache[I].Install() == true)
Fix.Protect(I);
@@ -421,7 +438,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache)
do
{
Change = false;
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
// Not interesting
if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true)
@@ -438,7 +455,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache)
Change = true;
}
}
- Count++;
+ ++Count;
}
while (Change == true && Count < 10);
@@ -525,7 +542,7 @@ void pkgProblemResolver::MakeScores()
<< " AddEssential => " << AddEssential << endl;
// Generate the base scores for a package based on its properties
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (Cache[I].InstallVer == 0)
continue;
@@ -552,12 +569,12 @@ void pkgProblemResolver::MakeScores()
}
// Now that we have the base scores we go and propogate dependencies
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ 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++)
+ for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D)
{
if (D->Type == pkgCache::Dep::Depends ||
D->Type == pkgCache::Dep::PreDepends)
@@ -574,12 +591,12 @@ void pkgProblemResolver::MakeScores()
/* Now we cause 1 level of dependency inheritance, that is we add the
score of the packages that depend on the target Package. This
fortifies high scoring packages */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (Cache[I].InstallVer == 0)
continue;
- for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; D++)
+ for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; ++D)
{
// Only do it for the install version
if ((pkgCache::Version *)D.ParentVer() != Cache[D.ParentPkg()].InstallVer ||
@@ -594,9 +611,9 @@ void pkgProblemResolver::MakeScores()
/* Now we propogate along provides. This makes the packages that
provide important packages extremely important */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
- for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; P++)
+ for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; ++P)
{
// Only do it once per package
if ((pkgCache::Version *)P.OwnerVer() != Cache[P.OwnerPkg()].InstallVer)
@@ -607,7 +624,7 @@ void pkgProblemResolver::MakeScores()
/* Protected things are pushed really high up. This number should put them
ahead of everything */
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if ((Flags[I->ID] & Protected) != 0)
Scores[I->ID] += AddProtected;
@@ -704,7 +721,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
if (Start == End)
break;
- Start++;
+ ++Start;
}
if (Fail == true)
break;
@@ -725,7 +742,20 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
return true;
}
/*}}}*/
-// ProblemResolver::Resolve - Run the resolution pass /*{{{*/
+// ProblemResolver::Resolve - calls a resolver to fix the situation /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgProblemResolver::Resolve(bool BrokenFix)
+{
+ 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);
+ }
+ return ResolveInternal(BrokenFix);
+}
+ /*}}}*/
+// ProblemResolver::ResolveInternal - Run the resolution pass /*{{{*/
// ---------------------------------------------------------------------
/* This routines works by calculating a score for each package. The score
is derived by considering the package's priority and all reverse
@@ -739,18 +769,16 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
The BrokenFix flag enables a mode where the algorithm tries to
upgrade packages to advoid problems. */
-bool pkgProblemResolver::Resolve(bool BrokenFix)
+bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
{
pkgDepCache::ActionGroup group(Cache);
- unsigned long Size = Cache.Head().PackageCount;
-
// Record which packages are marked for install
bool Again = false;
do
{
Again = false;
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if (Cache[I].Install() == true)
Flags[I->ID] |= PreInstalled;
@@ -774,14 +802,16 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
clog << "Starting" << endl;
MakeScores();
-
+
+ unsigned long const Size = Cache.Head().PackageCount;
+
/* We have to order the packages so that the broken fixing pass
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<pkgCache::Package *> PList = new pkgCache::Package *[Size];
pkgCache::Package **PEnd = PList;
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
*PEnd++ = I;
This = this;
qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
@@ -901,7 +931,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
}
else
{
- Start++;
+ ++Start;
// We only worry about critical deps.
if (Start.IsCritical() != true)
continue;
@@ -1150,7 +1180,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
{
// See if this is the result of a hold
pkgCache::PkgIterator I = Cache.PkgBegin();
- for (;I.end() != true; I++)
+ for (;I.end() != true; ++I)
{
if (Cache[I].InstBroken() == false)
continue;
@@ -1162,7 +1192,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
// set the auto-flags (mvo: I'm not sure if we _really_ need this)
pkgCache::PkgIterator I = Cache.PkgBegin();
- for (;I.end() != true; I++) {
+ for (;I.end() != true; ++I) {
if (Cache[I].NewInstall() && !(Flags[I->ID] & PreInstalled)) {
if(_config->FindI("Debug::pkgAutoRemove",false)) {
std::clog << "Resolve installed new pkg: " << I.FullName(false)
@@ -1176,6 +1206,31 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
return true;
}
/*}}}*/
+
+// ProblemResolver::BreaksInstOrPolicy - Check if the given pkg is broken/*{{{*/
+// ---------------------------------------------------------------------
+/* This checks if the given package is broken either by a hard dependency
+ (InstBroken()) or by introducing a new policy breakage e.g. new
+ unsatisfied recommends for a package that was in "policy-good" state
+
+ Note that this is not perfect as it will ignore further breakage
+ for already broken policy (recommends)
+*/
+bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I)
+{
+
+ // a broken install is always a problem
+ if (Cache[I].InstBroken() == true)
+ return true;
+
+ // a newly broken policy (recommends/suggests) is a problem
+ if (Cache[I].NowPolicyBroken() == false &&
+ Cache[I].InstPolicyBroken() == true)
+ return true;
+
+ return false;
+}
+
// ProblemResolver::ResolveByKeep - Resolve problems using keep /*{{{*/
// ---------------------------------------------------------------------
/* This is the work horse of the soft upgrade routine. It is very gental
@@ -1183,6 +1238,21 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
system was non-broken previously. */
bool pkgProblemResolver::ResolveByKeep()
{
+ 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);
+ }
+ return ResolveByKeepInternal();
+}
+ /*}}}*/
+// ProblemResolver::ResolveByKeepInternal - Resolve problems using keep /*{{{*/
+// ---------------------------------------------------------------------
+/* 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::ResolveByKeepInternal()
+{
pkgDepCache::ActionGroup group(Cache);
unsigned long Size = Cache.Head().PackageCount;
@@ -1195,7 +1265,7 @@ bool pkgProblemResolver::ResolveByKeep()
would cause the removal of even lower score packages. */
pkgCache::Package **PList = new pkgCache::Package *[Size];
pkgCache::Package **PEnd = PList;
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
*PEnd++ = I;
This = this;
qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
@@ -1220,9 +1290,12 @@ bool pkgProblemResolver::ResolveByKeep()
{
pkgCache::PkgIterator I(Cache,*K);
- if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false)
+ if (Cache[I].InstallVer == 0)
continue;
+ if (InstOrNewPolicyBroken(I) == false)
+ continue;
+
/* Keep the package. If this works then great, otherwise we have
to be significantly more agressive and manipulate its dependencies */
if ((Flags[I->ID] & Protected) == 0)
@@ -1230,7 +1303,7 @@ bool pkgProblemResolver::ResolveByKeep()
if (Debug == true)
clog << "Keeping package " << I.FullName(false) << endl;
Cache.MarkKeep(I, false, false);
- if (Cache[I].InstBroken() == false)
+ if (InstOrNewPolicyBroken(I) == false)
{
K = PList - 1;
continue;
@@ -1280,23 +1353,23 @@ bool pkgProblemResolver::ResolveByKeep()
Cache.MarkKeep(Pkg, false, false);
}
- if (Cache[I].InstBroken() == false)
+ if (InstOrNewPolicyBroken(I) == false)
break;
}
- if (Cache[I].InstBroken() == false)
+ if (InstOrNewPolicyBroken(I) == false)
break;
if (Start == End)
break;
- Start++;
+ ++Start;
}
- if (Cache[I].InstBroken() == false)
+ if (InstOrNewPolicyBroken(I) == false)
break;
}
- if (Cache[I].InstBroken() == true)
+ if (InstOrNewPolicyBroken(I) == true)
continue;
// Restart again.
@@ -1316,7 +1389,7 @@ void pkgProblemResolver::InstallProtect()
{
pkgDepCache::ActionGroup group(Cache);
- for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
{
if ((Flags[I->ID] & Protected) == Protected)
{
@@ -1396,7 +1469,7 @@ bool ListUpdate(pkgAcquireStatus &Stat,
bool Failed = false;
bool TransientNetworkFailure = false;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
- I != Fetcher.ItemsEnd(); I++)
+ I != Fetcher.ItemsEnd(); ++I)
{
if ((*I)->Status == pkgAcquire::Item::StatDone)
continue;