add options to disable specific checksums for Indexes
[apt.git] / apt-pkg / orderlist.cc
index 61d8d914e43b3bf6a52fc54c29b251b86dfc3402..a53854a2687124eff9a10791e0c65a7c6923471c 100644 (file)
@@ -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.
@@ -63,9 +63,6 @@
    ##################################################################### */
                                                                        /*}}}*/
 // 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/orderlist.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/error.h>
@@ -120,7 +117,8 @@ 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;
 
@@ -129,10 +127,14 @@ bool pkgOrderList::IsMissing(PkgIterator Pkg)
    
    if (FileList[Pkg->ID].empty() == false)
       return false;
    
    if (FileList[Pkg->ID].empty() == 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 */
@@ -178,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;
 }
                                                                        /*}}}*/
@@ -209,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++)
       {
@@ -218,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;
@@ -233,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;
@@ -247,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;
@@ -263,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;
 }
@@ -285,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)
@@ -391,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;
    
@@ -427,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;
    
@@ -436,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
@@ -528,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++;
@@ -587,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 
@@ -671,13 +691,12 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
    }   
    return true;
 }
    }   
    return true;
 }
-
+                                                                       /*}}}*/
 // OrderList::DepUnPackPreD - Critical UnPacking ordering with depends /*{{{*/
 // ---------------------------------------------------------------------
 /* Critical PreDepends (also configure immediate and essential) strives to
    ensure not only that all conflicts+predepends are met but that this
 // OrderList::DepUnPackPreD - Critical UnPacking ordering with depends /*{{{*/
 // ---------------------------------------------------------------------
 /* 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)
 {
@@ -867,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 || 
@@ -884,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;
@@ -895,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