]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/algorithms.cc
convert a lot of places to use IsNegative instead of checking by hand
[apt.git] / apt-pkg / algorithms.cc
index 12c5b87102903524ac50256b71630870711fec8c..2dae4258a964c1935201235e7c3a72c1f26172d4 100644 (file)
@@ -90,21 +90,6 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
    Describe(Pkg,cout,true,true);
    Sim.MarkInstall(Pkg,false);
 
-   if (strcmp(Pkg.Arch(),"all") == 0)
-   {
-      pkgCache::GrpIterator G = Pkg.Group();
-      pkgCache::GrpIterator iG = iPkg.Group();
-      for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
-      {
-        if (strcmp(P.Arch(), "all") == 0)
-           continue;
-        if (iG.FindPkg(P.Arch())->CurrentVer == 0)
-           continue;
-        Flags[P->ID] = 1;
-        Sim.MarkInstall(P, false);
-      }
-   }
-
    // Look for broken conflicts+predepends.
    for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
    {
@@ -116,9 +101,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)
@@ -150,19 +133,6 @@ bool pkgSimulate::Configure(PkgIterator iPkg)
    
    Flags[Pkg->ID] = 2;
 
-   if (strcmp(Pkg.Arch(),"all") == 0)
-   {
-      pkgCache::GrpIterator G = Pkg.Group();
-      for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
-      {
-        if (strcmp(P.Arch(), "all") == 0)
-           continue;
-        if (Flags[P->ID] == 1)
-           Flags[P->ID] = 2;
-      }
-   }
-
-//   Sim.MarkInstall(Pkg,false);
    if (Sim[Pkg].InstBroken() == true)
    {
       cout << "Conf " << Pkg.FullName(false) << " broken" << endl;
@@ -187,7 +157,7 @@ bool pkgSimulate::Configure(PkgIterator iPkg)
       }            
       cout << endl;
 
-      _error->Error("Conf Broken %s",Pkg.FullName(false));
+      _error->Error("Conf Broken %s",Pkg.FullName(false).c_str());
    }   
    else
    {
@@ -214,21 +184,6 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge)
    Flags[Pkg->ID] = 3;
    Sim.MarkDelete(Pkg);
 
-   if (strcmp(Pkg.Arch(),"all") == 0)
-   {
-      pkgCache::GrpIterator G = Pkg.Group();
-      pkgCache::GrpIterator iG = iPkg.Group();
-      for (pkgCache::PkgIterator P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
-      {
-        if (strcmp(P.Arch(), "all") == 0)
-           continue;
-        if (iG.FindPkg(P.Arch())->CurrentVer == 0)
-           continue;
-        Flags[P->ID] = 3;
-        Sim.MarkDelete(P);
-      }
-   }
-
    if (Purge == true)
       cout << "Purg ";
    else
@@ -290,7 +245,7 @@ bool pkgApplyStatus(pkgDepCache &Cache)
               Cache.MarkInstall(I, false, 0, false);
            else
               return _error->Error(_("The package %s needs to be reinstalled, "
-                                   "but I can't find an archive for it."),I.FullName(true));
+                                   "but I can't find an archive for it."),I.FullName(true).c_str());
         }
         
         continue;
@@ -325,7 +280,7 @@ bool pkgApplyStatus(pkgDepCache &Cache)
         default:
         if (I->InstState != pkgCache::State::Ok)
            return _error->Error("The package %s is not ok and I "
-                                "don't know how to fix it!",I.FullName(false));
+                                "don't know how to fix it!",I.FullName(false).c_str());
       }
    }
    return true;
@@ -374,6 +329,13 @@ bool pkgDistUpgrade(pkgDepCache &Cache)
 {
    pkgDepCache::ActionGroup group(Cache);
 
+   /* Upgrade all installed packages first without autoinst to help the resolver
+      in versioned or-groups to upgrade the old solver instead of installing
+      a new one (if the old solver is not the first one [anymore]) */
+   for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
+      if (I->CurrentVer != 0)
+        Cache.MarkInstall(I, false, 0, false);
+
    /* Auto upgrade all installed packages, this provides the basis 
       for the installation */
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
@@ -683,12 +645,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;
       }
@@ -733,9 +693,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)
@@ -847,6 +805,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
       not be possible for a loop to form (that is a < b < c and fixing b by
       changing a breaks c) */
    bool Change = true;
+   bool const TryFixByInstall = _config->FindB("pkgProblemResolver::FixByInstall", true);
    for (int Counter = 0; Counter != 10 && Change == true; Counter++)
    {
       Change = false;
@@ -863,7 +822,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
             (Flags[I->ID] & ReInstateTried) == 0)
         {
            if (Debug == true)
-              clog << " Try to Re-Instate " << I.FullName(false) << endl;
+              clog << " Try to Re-Instate (" << Counter << ") " << I.FullName(false) << endl;
            unsigned long OldBreaks = Cache.BrokenCount();
            pkgCache::Version *OldVer = Cache[I].InstallVer;
            Flags[I->ID] &= ReInstateTried;
@@ -886,7 +845,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
            continue;
         
         if (Debug == true)
-           clog << "Investigating " << I << endl;
+           clog << "Investigating (" << Counter << ") " << I << endl;
         
         // Isolate the problem dependency
         PackageKill KillList[100];
@@ -904,9 +863,9 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
            if (Start == End)
            {
               // Decide what to do
-              if (InOr == true)
+              if (InOr == true && OldEnd == LEnd)
               {
-                 if (OldEnd == LEnd && OrOp == OrRemove)
+                 if (OrOp == OrRemove)
                  {
                     if ((Flags[I->ID] & Protected) != Protected)
                     {
@@ -914,9 +873,9 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
                           clog << "  Or group remove for " << I.FullName(false) << endl;
                        Cache.MarkDelete(I);
                        Change = true;
-                    }               
-                 }               
-                 if (OldEnd == LEnd && OrOp == OrKeep)
+                    }
+                 }
+                 else if (OrOp == OrKeep)
                  {
                     if (Debug == true)
                        clog << "  Or group keep for " << I.FullName(false) << endl;
@@ -963,9 +922,7 @@ bool pkgProblemResolver::Resolve(bool 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)
@@ -986,6 +943,20 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
               pkgCache::VerIterator Ver(Cache,*V);
               pkgCache::PkgIterator Pkg = Ver.ParentPkg();
 
+               /* This is a conflicts, and the version we are looking
+                  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.IsNegative() == true)
+               {
+                  if (Debug) 
+                     clog << "  Conflicts//Breaks against version " 
+                          << Ver.VerStr() << " for " << Pkg.Name() 
+                          << " but that is not InstVer, ignoring"
+                          << endl;
+                  continue;
+               }
+
               if (Debug == true)
                  clog << "  Considering " << Pkg.FullName(false) << ' ' << (int)Scores[Pkg->ID] <<
                  " as a solution to " << I.FullName(false) << ' ' << (int)Scores[I->ID] << endl;
@@ -994,9 +965,7 @@ bool pkgProblemResolver::Resolve(bool 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)
@@ -1041,6 +1010,25 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
                           if (Counter > 1 && Scores[Pkg->ID] > Scores[I->ID])
                              Scores[I->ID] = Scores[Pkg->ID];
                        }
+                       else if (TryFixByInstall == true &&
+                                Start.TargetPkg()->CurrentVer == 0 &&
+                                Cache[Start.TargetPkg()].Delete() == false &&
+                                (Flags[Start.TargetPkg()->ID] & ToRemove) != ToRemove &&
+                                Cache.GetCandidateVer(Start.TargetPkg()).end() == false)
+                       {
+                          /* Before removing or keeping the package with the broken dependency
+                             try instead to install the first not previously installed package
+                             solving this dependency. This helps every time a previous solver
+                             is removed by the resolver because of a conflict or alike but it is
+                             dangerous as it could trigger new breaks/conflicts… */
+                          if (Debug == true)
+                             clog << "  Try Installing " << Start.TargetPkg() << " before changing " << I.FullName(false) << std::endl;
+                          unsigned long const OldBroken = Cache.BrokenCount();
+                          Cache.MarkInstall(Start.TargetPkg(), true, 1, false);
+                          // FIXME: we should undo the complete MarkInstall process here
+                          if (Cache[Start.TargetPkg()].InstBroken() == true || Cache.BrokenCount() > OldBroken)
+                             Cache.MarkDelete(Start.TargetPkg(), false, 1, false);
+                       }
                     }
                  }
                                  
@@ -1050,22 +1038,14 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
               }
               else
               {
-                 /* This is a conflicts, and the version we are looking
-                    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::Obsoletes))
-                    continue;
-
                  if (Start->Type == pkgCache::Dep::DpkgBreaks)
                  {
                     // first, try upgradring the package, if that
                     // does not help, the breaks goes onto the
                     // kill list
+                     //
                     // FIXME: use DoUpgrade(Pkg) instead?
-                    if (Cache[End] & pkgDepCache::DepGCVer) 
+                    if (Cache[End] & pkgDepCache::DepGCVer)
                     {
                        if (Debug)
                           clog << "  Upgrading " << Pkg.FullName(false) << " due to Breaks field in " << I.FullName(false) << endl;
@@ -1092,10 +1072,8 @@ bool pkgProblemResolver::Resolve(bool 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();
@@ -1141,9 +1119,7 @@ bool pkgProblemResolver::Resolve(bool 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;
@@ -1325,7 +1301,7 @@ bool pkgProblemResolver::ResolveByKeep()
       
       // Restart again.
       if (K == LastStop)
-        return _error->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I.FullName(false));
+        return _error->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I.FullName(false).c_str());
       LastStop = K;
       K = PList - 1;
    }   
@@ -1457,9 +1433,9 @@ bool ListUpdate(pkgAcquireStatus &Stat,
    }
    
    if (TransientNetworkFailure == true)
-      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+      _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
    else if (Failed == true)
-      return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+      return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
 
 
    // Run the success scripts if all was fine