]> 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 d9e0d2f813e8b03e71eddd5cd4df9ffb0111a34c..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;
@@ -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
@@ -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)
@@ -964,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)
@@ -987,21 +943,18 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
               pkgCache::VerIterator Ver(Cache,*V);
               pkgCache::PkgIterator Pkg = Ver.ParentPkg();
 
-               /* Ignore a target that is not a candidate
-                  This can happen if:
-                    installed package provides video-6
-                    candidate provides video-8
-                  now if a package Start breaks/conflicts video-6
-                  Start.AllTargets() will return the now-installed
-                  versions even though these are not candidates
-                  we can ignore them
-               */
-               if (Cache[Pkg].CandidateVerIter(Cache) != Ver)
+               /* 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)
                {
-                  clog << "  Version " << Ver.VerStr() << " for "
-                       << Pkg.Name() << " is not a candidate, ignoring"
-                       << endl;
-                 continue;
+                  if (Debug) 
+                     clog << "  Conflicts//Breaks against version " 
+                          << Ver.VerStr() << " for " << Pkg.Name() 
+                          << " but that is not InstVer, ignoring"
+                          << endl;
+                  continue;
                }
 
               if (Debug == true)
@@ -1012,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)
@@ -1062,6 +1013,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
                        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
@@ -1086,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 upgrading the package, if that
+                    // 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;
@@ -1122,17 +1066,14 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
                  LEnd++;
                  
                  if (Start->Type != pkgCache::Dep::Conflicts &&
-                      Start->Type != pkgCache::Dep::DpkgBreaks &&
                      Start->Type != pkgCache::Dep::Obsoletes)
                     break;
               }
            }
 
            // 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();
@@ -1178,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;
@@ -1494,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