]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/algorithms.cc
try xz instead of bz2 first for compressed files
[apt.git] / apt-pkg / algorithms.cc
index db1ebd7e3d57fc08387b3338e603bacf69ad75fb..6d982c551c98f5cd4aa81735244dc5b869a66f1e 100644 (file)
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.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/edsp.h>
 #include <apt-pkg/edsp.h>
-#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/progress.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 
-#include <sys/types.h>
+#include <string.h>
+#include <string>
 #include <cstdlib>
 #include <cstdlib>
-#include <algorithm>
 #include <iostream>
 #include <iostream>
-#include <stdio.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -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),
 /* 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)
 {
                            Sim(&Cache->GetCache(),&iPolicy),
                            group(Sim)
 {
@@ -446,31 +443,39 @@ void pkgProblemResolver::MakeScores()
          || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
         Score += PrioEssentials;
 
          || (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
       /* 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;
       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
    }
 
    // Copy the scores to advoid additive looping
-   SPtrArray<int> OldScores = new int[Size];
-   memcpy(OldScores,Scores,sizeof(*Scores)*Size);
+   std::unique_ptr<int[]> 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 
       
    /* 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    /*{{{*/
 }
                                                                        /*}}}*/
 // 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");
 {
    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);
 }
                                                                        /*}}}*/
    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. */
       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;
+   std::unique_ptr<pkgCache::Package *[]> PList(new pkgCache::Package *[Size]);
+   pkgCache::Package **PEnd = PList.get();
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
       *PEnd++ = I;
    This = this;
    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;
 
    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);
          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 (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);
 
       {
         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 */
            /* 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<pkgCache::Version *> VList = Start.AllTargets();
-           if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
+           std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+           if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected &&
                Start.IsNegative() == false &&
                Cache[I].NowBroken() == false)
            {          
                Start.IsNegative() == false &&
                Cache[I].NowBroken() == false)
            {          
@@ -860,7 +861,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
            }
            
            bool Done = false;
            }
            
            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();
            {
               pkgCache::VerIterator Ver(Cache,*V);
               pkgCache::PkgIterator Pkg = Ver.ParentPkg();
@@ -880,8 +881,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
                }
 
               if (Debug == true)
                }
 
               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 */
 
               /* 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. */
 /* 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");
 {
    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();
 }
                                                                        /*}}}*/
    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
               clog << "Package " << I.FullName(false) << " " << Start << endl;
 
            // Look at all the possible provides on this package
-           SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
-           for (pkgCache::Version **V = VList; *V != 0; V++)
+           std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+           for (pkgCache::Version **V = VList.get(); *V != 0; V++)
            {
               pkgCache::VerIterator Ver(Cache,*V);
               pkgCache::PkgIterator Pkg = Ver.ParentPkg();
            {
               pkgCache::VerIterator Ver(Cache,*V);
               pkgCache::PkgIterator Pkg = Ver.ParentPkg();