]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/orderlist.cc
add options to disable specific checksums for Indexes
[apt.git] / apt-pkg / orderlist.cc
index 4bd60372679d3099b110f54d8d6eccc4c9997eb2..a53854a2687124eff9a10791e0c65a7c6923471c 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: orderlist.cc,v 1.12 2001/02/20 07:03:17 jgg Exp $
+// $Id: orderlist.cc,v 1.14 2001/05/07 05:49:43 jgg Exp $
 /* ######################################################################
 
    Order List - Represents and Manipulates an ordered list of packages.
 /* ######################################################################
 
    Order List - Represents and Manipulates an ordered list of packages.
@@ -39,7 +39,7 @@
          ordering.  
    
    Each of the features can be enabled in the sorting routine at an 
          ordering.  
    
    Each of the features can be enabled in the sorting routine at an 
-   arbitary priority to give quite abit of control over the final unpacking
+   arbitrary priority to give quite abit of control over the final unpacking
    order.
 
    The rules listed above may never be violated and are called Critical.
    order.
 
    The rules listed above may never be violated and are called Critical.
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/orderlist.h"
-#endif 
 #include <apt-pkg/orderlist.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/orderlist.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/configuration.h>
+
+#include <iostream>
                                                                        /*}}}*/
 
                                                                        /*}}}*/
 
+using namespace std;
+
 pkgOrderList *pkgOrderList::Me = 0;
 
 // OrderList::pkgOrderList - Constructor                               /*{{{*/
 pkgOrderList *pkgOrderList::Me = 0;
 
 // OrderList::pkgOrderList - Constructor                               /*{{{*/
@@ -116,16 +117,24 @@ bool pkgOrderList::IsMissing(PkgIterator Pkg)
       return false;
 
    // Skip Packages that need configure only.
       return false;
 
    // Skip Packages that need configure only.
-   if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && 
+   if ((Pkg.State() == pkgCache::PkgIterator::NeedsConfigure ||
+        Pkg.State() == pkgCache::PkgIterator::NeedsNothing) &&
        Cache[Pkg].Keep() == true)
       return false;
        Cache[Pkg].Keep() == true)
       return false;
+
+   if (FileList == 0)
+      return false;
    
    
-   if (FileList != 0 && FileList[Pkg->ID].empty() == false)
+   if (FileList[Pkg->ID].empty() == false)
       return false;
       return false;
+
+   // Missing Pseudo packages are missing if the real package is missing
+   if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == true)
+      return IsMissing(Pkg.Group().FindPkg("all"));
+
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
-
 // OrderList::DoRun - Does an order run                                        /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expeted to have setup the desired probe state */
 // OrderList::DoRun - Does an order run                                        /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expeted to have setup the desired probe state */
@@ -171,22 +180,35 @@ bool pkgOrderList::DoRun()
 bool pkgOrderList::OrderCritical()
 {
    FileList = 0;
 bool pkgOrderList::OrderCritical()
 {
    FileList = 0;
-   
-   Primary = &pkgOrderList::DepUnPackPre;
+
+   Primary = &pkgOrderList::DepUnPackPreD;
    Secondary = 0;
    RevDepends = 0;
    Remove = 0;
    LoopCount = 0;
    Secondary = 0;
    RevDepends = 0;
    Remove = 0;
    LoopCount = 0;
-   
+
    // Sort
    Me = this;
    // Sort
    Me = this;
-   qsort(List,End - List,sizeof(*List),&OrderCompareB);   
-   
+   qsort(List,End - List,sizeof(*List),&OrderCompareB);
+
    if (DoRun() == false)
       return false;
    if (DoRun() == false)
       return false;
-   
+
    if (LoopCount != 0)
       return _error->Error("Fatal, predepends looping detected");
    if (LoopCount != 0)
       return _error->Error("Fatal, predepends looping detected");
+
+   if (Debug == true)
+   {
+      clog << "** Critical Unpack ordering done" << endl;
+
+      for (iterator I = List; I != End; I++)
+      {
+        PkgIterator P(Cache,*I);
+        if (IsNow(P) == true)
+           clog << "  " << P.FullName() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl;
+      }
+   }
+
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
@@ -202,7 +224,7 @@ bool pkgOrderList::OrderUnpack(string *FileList)
    if (FileList != 0)
    {
       WipeFlags(After);
    if (FileList != 0)
    {
       WipeFlags(After);
-      
+
       // Set the inlist flag
       for (iterator I = List; I != End; I++)
       {
       // Set the inlist flag
       for (iterator I = List; I != End; I++)
       {
@@ -211,7 +233,7 @@ bool pkgOrderList::OrderUnpack(string *FileList)
             Flag(*I,After);
       }
    }
             Flag(*I,After);
       }
    }
-   
+
    Primary = &pkgOrderList::DepUnPackCrit;
    Secondary = &pkgOrderList::DepConfigure;
    RevDepends = &pkgOrderList::DepUnPackDep;
    Primary = &pkgOrderList::DepUnPackCrit;
    Secondary = &pkgOrderList::DepConfigure;
    RevDepends = &pkgOrderList::DepUnPackDep;
@@ -226,7 +248,7 @@ bool pkgOrderList::OrderUnpack(string *FileList)
       clog << "** Pass A" << endl;
    if (DoRun() == false)
       return false;
       clog << "** Pass A" << endl;
    if (DoRun() == false)
       return false;
-   
+
    if (Debug == true)
       clog << "** Pass B" << endl;
    Secondary = 0;
    if (Debug == true)
       clog << "** Pass B" << endl;
    Secondary = 0;
@@ -240,7 +262,7 @@ bool pkgOrderList::OrderUnpack(string *FileList)
    Remove = 0;             // Otherwise the libreadline remove problem occures
    if (DoRun() == false)
       return false;
    Remove = 0;             // Otherwise the libreadline remove problem occures
    if (DoRun() == false)
       return false;
-      
+
    if (Debug == true)
       clog << "** Pass D" << endl;
    LoopCount = 0;
    if (Debug == true)
       clog << "** Pass D" << endl;
    LoopCount = 0;
@@ -256,9 +278,9 @@ bool pkgOrderList::OrderUnpack(string *FileList)
       {
         PkgIterator P(Cache,*I);
         if (IsNow(P) == true)
       {
         PkgIterator P(Cache,*I);
         if (IsNow(P) == true)
-           clog << P.Name() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl;
+           clog << "  " << P.FullName() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl;
       }
       }
-   }   
+   }
 
    return true;
 }
 
    return true;
 }
@@ -278,35 +300,40 @@ bool pkgOrderList::OrderConfigure()
    return DoRun();
 }
                                                                        /*}}}*/
    return DoRun();
 }
                                                                        /*}}}*/
-
 // OrderList::Score - Score the package for sorting                    /*{{{*/
 // ---------------------------------------------------------------------
 /* Higher scores order earlier */
 int pkgOrderList::Score(PkgIterator Pkg)
 {
 // OrderList::Score - Score the package for sorting                    /*{{{*/
 // ---------------------------------------------------------------------
 /* Higher scores order earlier */
 int pkgOrderList::Score(PkgIterator Pkg)
 {
+   static int const ScoreDelete = _config->FindI("OrderList::Score::Delete", 500);
+
    // Removal is always done first
    if (Cache[Pkg].Delete() == true)
    // Removal is always done first
    if (Cache[Pkg].Delete() == true)
-      return 200;
-   
+      return ScoreDelete;
+
    // This should never happen..
    if (Cache[Pkg].InstVerIter(Cache).end() == true)
       return -1;
    // This should never happen..
    if (Cache[Pkg].InstVerIter(Cache).end() == true)
       return -1;
-   
+
+   static int const ScoreEssential = _config->FindI("OrderList::Score::Essential", 200);
+   static int const ScoreImmediate = _config->FindI("OrderList::Score::Immediate", 10);
+   static int const ScorePreDepends = _config->FindI("OrderList::Score::PreDepends", 50);
+
    int Score = 0;
    if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
    int Score = 0;
    if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
-      Score += 100;
+      Score += ScoreEssential;
 
    if (IsFlag(Pkg,Immediate) == true)
 
    if (IsFlag(Pkg,Immediate) == true)
-      Score += 10;
-   
-   for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); 
+      Score += ScoreImmediate;
+
+   for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList();
        D.end() == false; D++)
       if (D->Type == pkgCache::Dep::PreDepends)
       {
        D.end() == false; D++)
       if (D->Type == pkgCache::Dep::PreDepends)
       {
-        Score += 50;
+        Score += ScorePreDepends;
         break;
       }
         break;
       }
-      
+
    // Important Required Standard Optional Extra
    signed short PrioMap[] = {0,5,4,3,1,0};
    if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5)
    // Important Required Standard Optional Extra
    signed short PrioMap[] = {0,5,4,3,1,0};
    if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5)
@@ -384,6 +411,7 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b)
    
    int ScoreA = Me->Score(A);
    int ScoreB = Me->Score(B);
    
    int ScoreA = Me->Score(A);
    int ScoreB = Me->Score(B);
+
    if (ScoreA > ScoreB)
       return -1;
    
    if (ScoreA > ScoreB)
       return -1;
    
@@ -420,6 +448,7 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b)
    
    int ScoreA = Me->Score(A);
    int ScoreB = Me->Score(B);
    
    int ScoreA = Me->Score(A);
    int ScoreB = Me->Score(B);
+
    if (ScoreA > ScoreB)
       return -1;
    
    if (ScoreA > ScoreB)
       return -1;
    
@@ -429,7 +458,6 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b)
    return strcmp(A.Name(),B.Name());
 }
                                                                        /*}}}*/
    return strcmp(A.Name(),B.Name());
 }
                                                                        /*}}}*/
-
 // OrderList::VisitDeps - Visit forward install dependencies           /*{{{*/
 // ---------------------------------------------------------------------
 /* This calls the dependency function for the normal forwards dependencies
 // OrderList::VisitDeps - Visit forward install dependencies           /*{{{*/
 // ---------------------------------------------------------------------
 /* This calls the dependency function for the normal forwards dependencies
@@ -484,11 +512,13 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
         continue;
       
       if (D->Type != pkgCache::Dep::Conflicts &&
         continue;
       
       if (D->Type != pkgCache::Dep::Conflicts &&
+         D->Type != pkgCache::Dep::DpkgBreaks &&
          D->Type != pkgCache::Dep::Obsoletes &&
          Cache[Pkg].InstallVer != *I)
         continue;
       
       if ((D->Type == pkgCache::Dep::Conflicts ||
          D->Type != pkgCache::Dep::Obsoletes &&
          Cache[Pkg].InstallVer != *I)
         continue;
       
       if ((D->Type == pkgCache::Dep::Conflicts ||
+          D->Type == pkgCache::Dep::DpkgBreaks ||
           D->Type == pkgCache::Dep::Obsoletes) &&
          (Version *)Pkg.CurrentVer() != *I)
         continue;
           D->Type == pkgCache::Dep::Obsoletes) &&
          (Version *)Pkg.CurrentVer() != *I)
         continue;
@@ -519,7 +549,7 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg)
    if (Debug == true)
    {
       for (int j = 0; j != Depth; j++) clog << ' ';
    if (Debug == true)
    {
       for (int j = 0; j != Depth; j++) clog << ' ';
-      clog << "Visit " << Pkg.Name() << endl;
+      clog << "Visit " << Pkg.FullName() << endl;
    }
    
    Depth++;
    }
    
    Depth++;
@@ -578,13 +608,12 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg)
    if (Debug == true)
    {
       for (int j = 0; j != Depth; j++) clog << ' ';
    if (Debug == true)
    {
       for (int j = 0; j != Depth; j++) clog << ' ';
-      clog << "Leave " << Pkg.Name() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl;
+      clog << "Leave " << Pkg.FullName() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl;
    }
    
    return true;
 }
                                                                        /*}}}*/
    }
    
    return true;
 }
                                                                        /*}}}*/
-
 // OrderList::DepUnPackCrit - Critical UnPacking ordering              /*{{{*/
 // ---------------------------------------------------------------------
 /* Critical unpacking ordering strives to satisfy Conflicts: and 
 // OrderList::DepUnPackCrit - Critical UnPacking ordering              /*{{{*/
 // ---------------------------------------------------------------------
 /* Critical unpacking ordering strives to satisfy Conflicts: and 
@@ -623,6 +652,7 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
         /* Forward critical dependencies MUST be correct before the 
            package can be unpacked. */
         if (D->Type != pkgCache::Dep::Conflicts &&
         /* Forward critical dependencies MUST be correct before the 
            package can be unpacked. */
         if (D->Type != pkgCache::Dep::Conflicts &&
+            D->Type != pkgCache::Dep::DpkgBreaks &&
             D->Type != pkgCache::Dep::Obsoletes &&
             D->Type != pkgCache::Dep::PreDepends)
            continue;
             D->Type != pkgCache::Dep::Obsoletes &&
             D->Type != pkgCache::Dep::PreDepends)
            continue;
@@ -666,8 +696,7 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
 // ---------------------------------------------------------------------
 /* Critical PreDepends (also configure immediate and essential) strives to
    ensure not only that all conflicts+predepends are met but that this
 // ---------------------------------------------------------------------
 /* Critical PreDepends (also configure immediate and essential) strives to
    ensure not only that all conflicts+predepends are met but that this
-   package will be immediately configurable when it is unpacked. 
-
+   package will be immediately configurable when it is unpacked.
    Loops are preprocessed and logged. */
 bool pkgOrderList::DepUnPackPreD(DepIterator D)
 {
    Loops are preprocessed and logged. */
 bool pkgOrderList::DepUnPackPreD(DepIterator D)
 {
@@ -796,9 +825,20 @@ bool pkgOrderList::DepUnPackDep(DepIterator D)
               return false;
         }
         else
               return false;
         }
         else
+        {
            if (D->Type == pkgCache::Dep::Depends)
               if (VisitProvides(D,false) == false)
                  return false;
            if (D->Type == pkgCache::Dep::Depends)
               if (VisitProvides(D,false) == false)
                  return false;
+
+           if (D->Type == pkgCache::Dep::DpkgBreaks)
+           {
+              if (CheckDep(D) == true)
+                continue;
+
+              if (VisitNode(D.TargetPkg()) == false)
+                return false;
+           }
+        }
       }
    return true;
 }
       }
    return true;
 }
@@ -846,13 +886,16 @@ bool pkgOrderList::DepRemove(DepIterator D)
            continue;
 
         /* We wish to see if the dep on the parent package is okay
            continue;
 
         /* We wish to see if the dep on the parent package is okay
-           in the removed (install) state of the target pkg. */         
+           in the removed (install) state of the target pkg. */
+        bool tryFixDeps = false;
         if (CheckDep(D) == true)
         {
            // We want to catch loops with the code below.
            if (IsFlag(D.ParentPkg(),AddPending) == false)
               continue;
         }
         if (CheckDep(D) == true)
         {
            // We want to catch loops with the code below.
            if (IsFlag(D.ParentPkg(),AddPending) == false)
               continue;
         }
+        else
+           tryFixDeps = true;
 
         // This is the loop detection
         if (IsFlag(D.ParentPkg(),Added) == true || 
 
         // This is the loop detection
         if (IsFlag(D.ParentPkg(),Added) == true || 
@@ -863,6 +906,100 @@ bool pkgOrderList::DepRemove(DepIterator D)
            continue;
         }
 
            continue;
         }
 
+        if (tryFixDeps == true)
+        {
+           for (pkgCache::DepIterator F = D.ParentPkg().CurrentVer().DependsList();
+                F.end() == false; ++F)
+           {
+              if (F->Type != pkgCache::Dep::Depends && F->Type != pkgCache::Dep::PreDepends)
+                 continue;
+              // Check the Providers
+              if (F.TargetPkg()->ProvidesList != 0)
+              {
+                 pkgCache::PrvIterator Prov = F.TargetPkg().ProvidesList();
+                 for (; Prov.end() == false; ++Prov)
+                 {
+                    pkgCache::PkgIterator const P = Prov.OwnerPkg();
+                    if (IsFlag(P, InList) == true &&
+                        IsFlag(P, AddPending) == true &&
+                        IsFlag(P, Added) == false &&
+                        Cache[P].InstallVer == 0)
+                       break;
+                 }
+                 if (Prov.end() == false)
+                    for (pkgCache::PrvIterator Prv = F.TargetPkg().ProvidesList();
+                         Prv.end() == false; ++Prv)
+                    {
+                       pkgCache::PkgIterator const P = Prv.OwnerPkg();
+                       if (IsFlag(P, InList) == true &&
+                           IsFlag(P, AddPending) == false &&
+                           Cache[P].InstallVer != 0 &&
+                           VisitNode(P) == true)
+                       {
+                          Flag(P, Immediate);
+                          tryFixDeps = false;
+                          break;
+                       }
+                    }
+                 if (tryFixDeps == false)
+                    break;
+              }
+
+              // Check for Or groups
+              if ((F->CompareOp & pkgCache::Dep::Or) != pkgCache::Dep::Or)
+                 continue;
+              // Lets see if the package is part of the Or group
+              pkgCache::DepIterator S = F;
+              for (; S.end() == false; ++S)
+              {
+                 if (S.TargetPkg() == D.TargetPkg())
+                    break;
+                 if ((S->CompareOp & pkgCache::Dep::Or) != pkgCache::Dep::Or ||
+                     CheckDep(S)) // Or group is satisfied by another package
+                    for (;S.end() == false; ++S);
+              }
+              if (S.end() == true)
+                 continue;
+              // skip to the end of the or group
+              for (;S.end() == false && (S->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; ++S);
+              ++S;
+              // The soon to be removed is part of the Or group
+              // start again in the or group and find something which will serve as replacement
+              for (; F.end() == false && F != S; ++F)
+              {
+                 if (IsFlag(F.TargetPkg(), InList) == true &&
+                     IsFlag(F.TargetPkg(), AddPending) == false &&
+                     Cache[F.TargetPkg()].InstallVer != 0 &&
+                     VisitNode(F.TargetPkg()) == true)
+                 {
+                    Flag(F.TargetPkg(), Immediate);
+                    tryFixDeps = false;
+                    break;
+                 }
+                 else if (F.TargetPkg()->ProvidesList != 0)
+                 {
+                    pkgCache::PrvIterator Prv = F.TargetPkg().ProvidesList();
+                    for (; Prv.end() == false; ++Prv)
+                    {
+                       if (IsFlag(Prv.OwnerPkg(), InList) == true &&
+                           IsFlag(Prv.OwnerPkg(), AddPending) == false &&
+                           Cache[Prv.OwnerPkg()].InstallVer != 0 &&
+                           VisitNode(Prv.OwnerPkg()) == true)
+                       {
+                          Flag(Prv.OwnerPkg(), Immediate);
+                          tryFixDeps = false;
+                          break;
+                       }
+                    }
+                    if (Prv.end() == false)
+                       break;
+                 }
+              }
+              if (tryFixDeps == false)
+                 break;
+           }
+        }
+
         // Skip over missing files
         if (IsMissing(D.ParentPkg()) == true)
            continue;
         // Skip over missing files
         if (IsMissing(D.ParentPkg()) == true)
            continue;
@@ -874,7 +1011,6 @@ bool pkgOrderList::DepRemove(DepIterator D)
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
-
 // OrderList::AddLoop - Add a loop to the loop list                    /*{{{*/
 // ---------------------------------------------------------------------
 /* We record the loops. This is a relic since loop breaking is done 
 // OrderList::AddLoop - Add a loop to the loop list                    /*{{{*/
 // ---------------------------------------------------------------------
 /* We record the loops. This is a relic since loop breaking is done 
@@ -946,6 +1082,7 @@ bool pkgOrderList::CheckDep(DepIterator D)
       /* Conflicts requires that all versions are not present, depends
          just needs one */
       if (D->Type != pkgCache::Dep::Conflicts && 
       /* Conflicts requires that all versions are not present, depends
          just needs one */
       if (D->Type != pkgCache::Dep::Conflicts && 
+         D->Type != pkgCache::Dep::DpkgBreaks && 
          D->Type != pkgCache::Dep::Obsoletes)
       {
         /* Try to find something that does not have the after flag set
          D->Type != pkgCache::Dep::Obsoletes)
       {
         /* Try to find something that does not have the after flag set