]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/algorithms.cc
reorder includes: add <config.h> if needed and include it at first
[apt.git] / apt-pkg / algorithms.cc
index b55ff2897ad9df37c42f06bd21456228fa6c4985..d5652791c1a1964fe0d0f14c56aa7f1ce2ea0dda 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // 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 <apt-pkg/edspwriter.h>
+#include <apt-pkg/edsp.h>
 
-#include <apti18n.h>
 #include <sys/types.h>
 #include <cstdlib>
 #include <algorithm>
 #include <iostream>
-
 #include <stdio.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 using namespace std;
 
@@ -104,9 +106,7 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
         DepIterator Start;
         DepIterator End;
         D.GlobOr(Start,End);
-        if (Start->Type == pkgCache::Dep::Conflicts ||
-            Start->Type == pkgCache::Dep::DpkgBreaks ||
-            Start->Type == pkgCache::Dep::Obsoletes ||
+        if (Start.IsNegative() == true ||
             End->Type == pkgCache::Dep::PreDepends)
          {
            if ((Sim[End] & pkgDepCache::DepGInstall) == 0)
@@ -332,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
@@ -384,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);
@@ -650,12 +662,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
       // Compute a single dependency element (glob or)
       pkgCache::DepIterator Start = D;
       pkgCache::DepIterator End = D;
-      unsigned char State = 0;
       for (bool LastOR = true; D.end() == false && LastOR == true;)
       {
-        State |= Cache[D];
         LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
-        D++;
+        ++D;
         if (LastOR == true)
            End = D;
       }
@@ -700,9 +710,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
            {
               /* We let the algorithm deal with conflicts on its next iteration,
                it is much smarter than us */
-              if (Start->Type == pkgCache::Dep::Conflicts || 
-                  Start->Type == pkgCache::Dep::DpkgBreaks || 
-                  Start->Type == pkgCache::Dep::Obsoletes)
+              if (Start.IsNegative() == true)
                   break;
               
               if (Debug == true)
@@ -739,21 +747,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
 /* */
 bool pkgProblemResolver::Resolve(bool BrokenFix)
 {
-   std::string const solver = _config->Find("APT::Solver::Name", "internal");
-   if (solver != "internal")
-   {
-      FILE* output = fopen("/tmp/scenario.log", "w");
-      edspWriter::WriteScenario(Cache, output);
-      fclose(output);
-      output = fopen("/tmp/request.log", "w");
-      edspWriter::WriteRequest(Cache, output);
-      fclose(output);
-      if (ResolveInternal(BrokenFix) == false)
-        return false;
-      output = fopen("/tmp/solution.log", "w");
-      edspWriter::WriteSolution(Cache, output);
-      fclose(output);
-      return true;
+   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);
 }
@@ -955,9 +952,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
               if a package has a dep on another package that cant be found */
            SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
            if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
-               Start->Type != pkgCache::Dep::Conflicts &&
-               Start->Type != pkgCache::Dep::DpkgBreaks &&
-               Start->Type != pkgCache::Dep::Obsoletes &&
+               Start.IsNegative() == false &&
                Cache[I].NowBroken() == false)
            {          
               if (InOr == true)
@@ -982,10 +977,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
                   at is not the currently selected version of the 
                   package, which means it is not necessary to 
                   remove/keep */
-               if (Cache[Pkg].InstallVer != Ver &&
-                   (Start->Type == pkgCache::Dep::Conflicts ||
-                    Start->Type == pkgCache::Dep::DpkgBreaks ||
-                    Start->Type == pkgCache::Dep::Obsoletes)) 
+               if (Cache[Pkg].InstallVer != Ver && Start.IsNegative() == true)
                {
                   if (Debug) 
                      clog << "  Conflicts//Breaks against version " 
@@ -1003,9 +995,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
                  fiddle with the VList package */
               if (Scores[I->ID] <= Scores[Pkg->ID] ||
                   ((Cache[Start] & pkgDepCache::DepNow) == 0 &&
-                   End->Type != pkgCache::Dep::Conflicts &&
-                   End->Type != pkgCache::Dep::DpkgBreaks &&
-                   End->Type != pkgCache::Dep::Obsoletes))
+                   End.IsNegative() == false))
               {
                  // Try a little harder to fix protected packages..
                  if ((Flags[I->ID] & Protected) == Protected)
@@ -1112,10 +1102,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
            }
 
            // Hm, nothing can possibly satisify this dep. Nuke it.
-           if (VList[0] == 0 && 
-               Start->Type != pkgCache::Dep::Conflicts &&
-               Start->Type != pkgCache::Dep::DpkgBreaks &&
-               Start->Type != pkgCache::Dep::Obsoletes &&
+           if (VList[0] == 0 &&
+               Start.IsNegative() == false &&
                (Flags[I->ID] & Protected) != Protected)
            {
               bool Installed = Cache[I].Install();
@@ -1161,9 +1149,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
               Change = true;
               if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0)
               {
-                 if (J->Dep->Type == pkgCache::Dep::Conflicts || 
-                     J->Dep->Type == pkgCache::Dep::DpkgBreaks ||
-                     J->Dep->Type == pkgCache::Dep::Obsoletes)
+                 if (J->Dep.IsNegative() == true)
                  {
                     if (Debug == true)
                        clog << "  Fixing " << I.FullName(false) << " via remove of " << J->Pkg.FullName(false) << endl;
@@ -1220,12 +1206,52 @@ bool pkgProblemResolver::ResolveInternal(bool const 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 
    in that it does not install or remove any packages. It is assumed that the
    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);
 
@@ -1264,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)
@@ -1274,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;
@@ -1324,11 +1353,11 @@ 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)
@@ -1336,11 +1365,11 @@ bool pkgProblemResolver::ResolveByKeep()
            Start++;
         }
              
-        if (Cache[I].InstBroken() == false)
+        if (InstOrNewPolicyBroken(I) == false)
            break;
       }
 
-      if (Cache[I].InstBroken() == true)
+      if (InstOrNewPolicyBroken(I) == true)
         continue;
       
       // Restart again.