Join with aliencode
[ntk/apt.git] / apt-pkg / orderlist.cc
index f79a063..4bd6037 100644 (file)
@@ -1,13 +1,13 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: orderlist.cc,v 1.1 1998/07/07 04:17:01 jgg Exp $
+// $Id: orderlist.cc,v 1.12 2001/02/20 07:03:17 jgg Exp $
 /* ######################################################################
 
    Order List - Represents and Manipulates an ordered list of packages.
    
    A list of packages can be ordered by a number of conflicting criteria
    each given a specific priority. Each package also has a set of flags
-   indicating some usefull things about it that are derived in the 
+   indicating some useful things about it that are derived in the 
    course of sorting. The pkgPackageManager class uses this class for
    all of it's installation ordering needs.
 
    arbitary priority to give quite abit of control over the final unpacking
    order.
 
-   The rules listed above my never be violated and are called Critical.
+   The rules listed above may never be violated and are called Critical.
    When a critical rule is violated then a loop condition is recorded
    and will have to be delt with in the caller.
+
+   The ordering keeps two lists, the main list and the 'After List'. The
+   purpose of the after list is to allow packages to be delayed. This is done
+   by setting the after flag on the package. Any package which requires this
+   package to be ordered before will inherit the after flag and so on. This
+   is used for CD swap ordering where all packages on a second CD have the 
+   after flag set. This forces them and all their dependents to be ordered
+   toward the end.
+   
+   There are complications in this algorithm when presented with cycles.
+   For all known practical cases it works, all cases where it doesn't work
+   is fixable by tweaking the package descriptions. However, it should be
+   possible to impove this further to make some better choices when 
+   presented with cycles. 
    
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
 #ifdef __GNUG__
-#pragma implementation "pkglib/orderlist.h"
+#pragma implementation "apt-pkg/orderlist.h"
 #endif 
-#include <pkglib/orderlist.h>
-#include <pkglib/depcache.h>
-#include <pkglib/error.h>
-#include <pkglib/version.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>
                                                                        /*}}}*/
 
 pkgOrderList *pkgOrderList::Me = 0;
@@ -63,18 +79,20 @@ pkgOrderList *pkgOrderList::Me = 0;
 // OrderList::pkgOrderList - Constructor                               /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgOrderList::pkgOrderList(pkgDepCache &Cache) : Cache(Cache)
+pkgOrderList::pkgOrderList(pkgDepCache *pCache) : Cache(*pCache)
 {
+   FileList = 0;
    Primary = 0;
    Secondary = 0;
    RevDepends = 0;
    Remove = 0;
    LoopCount = -1;
-
+   Debug = _config->FindB("Debug::pkgOrderList",false);
+   
    /* Construct the arrays, egcs 1.0.1 bug requires the package count
       hack */
-   unsigned long Size = Cache.HeaderP->PackageCount;
-   Flags = new unsigned char[Size];
+   unsigned long Size = Cache.Head().PackageCount;
+   Flags = new unsigned short[Size];
    End = List = new Package *[Size];
    memset(Flags,0,sizeof(*Flags)*Size);
 }
@@ -88,22 +106,43 @@ pkgOrderList::~pkgOrderList()
    delete [] Flags;
 }
                                                                        /*}}}*/
+// OrderList::IsMissing - Check if a file is missing                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgOrderList::IsMissing(PkgIterator Pkg) 
+{
+   // Skip packages to erase
+   if (Cache[Pkg].Delete() == true)
+      return false;
+
+   // Skip Packages that need configure only.
+   if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && 
+       Cache[Pkg].Keep() == true)
+      return false;
+   
+   if (FileList != 0 && FileList[Pkg->ID].empty() == false)
+      return false;
+   return true;
+}
+                                                                       /*}}}*/
 
 // OrderList::DoRun - Does an order run                                        /*{{{*/
 // ---------------------------------------------------------------------
 /* The caller is expeted to have setup the desired probe state */
 bool pkgOrderList::DoRun()
-{
+{   
    // Temp list
-   unsigned long Size = Cache.HeaderP->PackageCount;
-   Package **NList = new Package *[Size];
-
+   unsigned long Size = Cache.Head().PackageCount;
+   SPtrArray<Package *> NList = new Package *[Size];
+   SPtrArray<Package *> AfterList = new Package *[Size];
+   AfterEnd = AfterList;
+   
    Depth = 0;
    WipeFlags(Added | AddPending | Loop | InList);
 
    for (iterator I = List; I != End; I++)
       Flag(*I,InList);
-   
+
    // Rebuild the main list into the temp list.
    iterator OldEnd = End;
    End = NList;
@@ -111,13 +150,16 @@ bool pkgOrderList::DoRun()
       if (VisitNode(PkgIterator(Cache,*I)) == false)
       {
         End = OldEnd;
-        delete [] NList;
         return false;
       }
    
+   // Copy the after list to the end of the main list
+   for (Package **I = AfterList; I != AfterEnd; I++)
+      *End++ = *I;
+   
    // Swap the main list to the new list
    delete [] List;
-   List = NList;
+   List = NList.UnGuard();
    return true;
 }
                                                                        /*}}}*/
@@ -128,7 +170,9 @@ bool pkgOrderList::DoRun()
    fatal and indicate that the packages cannot be installed. */
 bool pkgOrderList::OrderCritical()
 {
-   Primary = &DepUnPackPre;
+   FileList = 0;
+   
+   Primary = &pkgOrderList::DepUnPackPre;
    Secondary = 0;
    RevDepends = 0;
    Remove = 0;
@@ -150,43 +194,71 @@ bool pkgOrderList::OrderCritical()
 // ---------------------------------------------------------------------
 /* This performs complete unpacking ordering and creates an order that is
    suitable for unpacking */
-bool pkgOrderList::OrderUnpack()
+bool pkgOrderList::OrderUnpack(string *FileList)
 {
-   Primary = &DepUnPackCrit;
-   Secondary = &DepConfigure;
-   RevDepends = &DepUnPackDep;
-   Remove = &DepRemove;
+   this->FileList = FileList;
+
+   // Setup the after flags
+   if (FileList != 0)
+   {
+      WipeFlags(After);
+      
+      // Set the inlist flag
+      for (iterator I = List; I != End; I++)
+      {
+        PkgIterator P(Cache,*I);
+        if (IsMissing(P) == true && IsNow(P) == true)
+            Flag(*I,After);
+      }
+   }
+   
+   Primary = &pkgOrderList::DepUnPackCrit;
+   Secondary = &pkgOrderList::DepConfigure;
+   RevDepends = &pkgOrderList::DepUnPackDep;
+   Remove = &pkgOrderList::DepRemove;
    LoopCount = -1;
 
    // Sort
    Me = this;
    qsort(List,End - List,sizeof(*List),&OrderCompareA);
-   
+
+   if (Debug == true)
+      clog << "** Pass A" << endl;
    if (DoRun() == false)
       return false;
    
+   if (Debug == true)
+      clog << "** Pass B" << endl;
    Secondary = 0;
    if (DoRun() == false)
       return false;
 
+   if (Debug == true)
+      clog << "** Pass C" << endl;
    LoopCount = 0;
    RevDepends = 0;
    Remove = 0;             // Otherwise the libreadline remove problem occures
    if (DoRun() == false)
       return false;
-
+      
+   if (Debug == true)
+      clog << "** Pass D" << endl;
    LoopCount = 0;
-   Primary = &DepUnPackPre;
+   Primary = &pkgOrderList::DepUnPackPre;
    if (DoRun() == false)
       return false;
 
-/*   cout << "----------END" << endl;
-
-   for (iterator I = List; I != End; I++)
+   if (Debug == true)
    {
-      PkgIterator P(Cache,*I);
-      cout << P.Name() << endl;
-   }*/
+      clog << "** Unpack ordering done" << endl;
+
+      for (iterator I = List; I != End; I++)
+      {
+        PkgIterator P(Cache,*I);
+        if (IsNow(P) == true)
+           clog << P.Name() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl;
+      }
+   }   
 
    return true;
 }
@@ -197,7 +269,8 @@ bool pkgOrderList::OrderUnpack()
    for configuration */
 bool pkgOrderList::OrderConfigure()
 {
-   Primary = &DepConfigure;
+   FileList = 0;
+   Primary = &pkgOrderList::DepConfigure;
    Secondary = 0;
    RevDepends = 0;
    Remove = 0;
@@ -214,11 +287,18 @@ int pkgOrderList::Score(PkgIterator Pkg)
    // Removal is always done first
    if (Cache[Pkg].Delete() == true)
       return 200;
-
+   
+   // This should never happen..
+   if (Cache[Pkg].InstVerIter(Cache).end() == true)
+      return -1;
+   
    int Score = 0;
    if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
       Score += 100;
 
+   if (IsFlag(Pkg,Immediate) == true)
+      Score += 10;
+   
    for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); 
        D.end() == false; D++)
       if (D->Type == pkgCache::Dep::PreDepends)
@@ -248,7 +328,7 @@ int pkgOrderList::FileCmp(PkgIterator A,PkgIterator B)
    
    if (Cache[A].InstVerIter(Cache).FileList().end() == true)
       return -1;
-   if (Cache[A].InstVerIter(Cache).FileList().end() == true)
+   if (Cache[B].InstVerIter(Cache).FileList().end() == true)
       return 1;
    
    pkgCache::PackageFile *FA = Cache[A].InstVerIter(Cache).FileList().File();
@@ -260,6 +340,18 @@ int pkgOrderList::FileCmp(PkgIterator A,PkgIterator B)
    return 0;
 }
                                                                        /*}}}*/
+// BoolCompare - Comparison function for two booleans                  /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+static int BoolCompare(bool A,bool B)
+{
+   if (A == B)
+      return 0;
+   if (A == false)
+      return -1;
+   return 1;
+}
+                                                                       /*}}}*/
 // OrderList::OrderCompareA - Order the installation by op             /*{{{*/
 // ---------------------------------------------------------------------
 /* This provides a first-pass sort of the list and gives a decent starting
@@ -269,6 +361,19 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b)
    PkgIterator A(Me->Cache,*(Package **)a);
    PkgIterator B(Me->Cache,*(Package **)b);
 
+   // We order packages with a set state toward the front
+   int Res;
+   if ((Res = BoolCompare(Me->IsNow(A),Me->IsNow(B))) != 0)
+      return -1*Res;
+   
+   // We order missing files to toward the end
+/*   if (Me->FileList != 0)
+   {
+      if ((Res = BoolCompare(Me->IsMissing(A),
+                            Me->IsMissing(B))) != 0)
+        return Res;
+   }*/
+   
    if (A.State() != pkgCache::PkgIterator::NeedsNothing && 
        B.State() == pkgCache::PkgIterator::NeedsNothing)
       return -1;
@@ -290,7 +395,7 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b)
                                                                        /*}}}*/
 // OrderList::OrderCompareB - Order the installation by source         /*{{{*/
 // ---------------------------------------------------------------------
-/* This orders by installation source. This is usefull to handle
+/* This orders by installation source. This is useful to handle
    inter-source breaks */
 int pkgOrderList::OrderCompareB(const void *a, const void *b)
 {
@@ -367,30 +472,34 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver)
 // OrderList::VisitProvides - Visit all of the providing packages      /*{{{*/
 // ---------------------------------------------------------------------
 /* This routine calls visit on all providing packages. */
-bool pkgOrderList::VisitProvides(DepIterator D)
-{
-   Version **List = D.AllTargets();
+bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
+{   
+   SPtrArray<Version *> List = D.AllTargets();
    for (Version **I = List; *I != 0; I++)
    {
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
-      
-      if (Cache[Pkg].Keep() == true)
+
+      if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)
         continue;
       
-      if (D->Type != pkgCache::Dep::Conflicts && Cache[Pkg].InstallVer != *I)
+      if (D->Type != pkgCache::Dep::Conflicts &&
+         D->Type != pkgCache::Dep::Obsoletes &&
+         Cache[Pkg].InstallVer != *I)
         continue;
       
-      if (D->Type == pkgCache::Dep::Conflicts && (Version *)Pkg.CurrentVer() != *I)
+      if ((D->Type == pkgCache::Dep::Conflicts ||
+          D->Type == pkgCache::Dep::Obsoletes) &&
+         (Version *)Pkg.CurrentVer() != *I)
         continue;
       
+      // Skip over missing files
+      if (Critical == false && IsMissing(D.ParentPkg()) == true)
+        continue;
+
       if (VisitNode(Pkg) == false)
-      {
-        delete [] List;
         return false;
-      }
    }
-   delete [] List;
    return true;
 }
                                                                        /*}}}*/
@@ -402,12 +511,17 @@ bool pkgOrderList::VisitProvides(DepIterator D)
 bool pkgOrderList::VisitNode(PkgIterator Pkg)
 {
    // Looping or irrelevent.
+   // This should probably trancend not installed packages
    if (Pkg.end() == true || IsFlag(Pkg,Added) == true || 
        IsFlag(Pkg,AddPending) == true || IsFlag(Pkg,InList) == false)
       return true;
 
-/* for (int j = 0; j != Depth; j++) cout << ' ';
- cout << "Visit " << Pkg.Name() << endl;*/
+   if (Debug == true)
+   {
+      for (int j = 0; j != Depth; j++) clog << ' ';
+      clog << "Visit " << Pkg.Name() << endl;
+   }
+   
    Depth++;
    
    // Color grey
@@ -416,49 +530,57 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg)
    DepFunc Old = Primary;
    
    // Perform immedate configuration of the package if so flagged.
-   if (IsFlag(Pkg,Immediate) == true && Primary != &DepUnPackPre)
-      Primary = &DepUnPackPreD;
-      
-   bool Res = true;
-   if (Cache[Pkg].Delete() == false)
+   if (IsFlag(Pkg,Immediate) == true && Primary != &pkgOrderList::DepUnPackPre)
+      Primary = &pkgOrderList::DepUnPackPreD;
+
+   if (IsNow(Pkg) == true)
    {
-      // Primary
-      Res &= Res && VisitDeps(Primary,Pkg);
-      Res &= Res && VisitRDeps(Primary,Pkg);
-      Res &= Res && VisitRProvides(Primary,Pkg.CurrentVer());
-      Res &= Res && VisitRProvides(Primary,Cache[Pkg].InstVerIter(Cache));
-      
-      // RevDep
-      Res &= Res && VisitRDeps(RevDepends,Pkg);
-      Res &= Res && VisitRProvides(RevDepends,Pkg.CurrentVer());
-      Res &= Res && VisitRProvides(RevDepends,Cache[Pkg].InstVerIter(Cache));
-       
-      // Secondary
-      Res &= Res && VisitDeps(Secondary,Pkg);
-      Res &= Res && VisitRDeps(Secondary,Pkg);
-      Res &= Res && VisitRProvides(Secondary,Pkg.CurrentVer());
-      Res &= Res && VisitRProvides(Secondary,Cache[Pkg].InstVerIter(Cache));
-   }
-   else
-   { 
-      // RevDep
-      Res &= Res && VisitRDeps(Remove,Pkg);
-      Res &= Res && VisitRProvides(Remove,Pkg.CurrentVer());
+      bool Res = true;
+      if (Cache[Pkg].Delete() == false)
+      {
+        // Primary
+        Res &= Res && VisitDeps(Primary,Pkg);
+        Res &= Res && VisitRDeps(Primary,Pkg);
+        Res &= Res && VisitRProvides(Primary,Pkg.CurrentVer());
+        Res &= Res && VisitRProvides(Primary,Cache[Pkg].InstVerIter(Cache));
+        
+        // RevDep
+        Res &= Res && VisitRDeps(RevDepends,Pkg);
+        Res &= Res && VisitRProvides(RevDepends,Pkg.CurrentVer());
+        Res &= Res && VisitRProvides(RevDepends,Cache[Pkg].InstVerIter(Cache));
+        
+        // Secondary
+        Res &= Res && VisitDeps(Secondary,Pkg);
+        Res &= Res && VisitRDeps(Secondary,Pkg);
+        Res &= Res && VisitRProvides(Secondary,Pkg.CurrentVer());
+        Res &= Res && VisitRProvides(Secondary,Cache[Pkg].InstVerIter(Cache));
+      }
+      else
+      { 
+        // RevDep
+        Res &= Res && VisitRDeps(Remove,Pkg);
+        Res &= Res && VisitRProvides(Remove,Pkg.CurrentVer());
+      }
    }
-
+   
    if (IsFlag(Pkg,Added) == false)
    {
       Flag(Pkg,Added,Added | AddPending);
-      *End = Pkg;
-      End++;
+      if (IsFlag(Pkg,After) == true)
+        *AfterEnd++ = Pkg;
+      else
+        *End++ = Pkg;
    }
    
    Primary = Old;
    Depth--;
-   
-/* for (int j = 0; j != Depth; j++) cout << ' ';
-   cout << "Leave " << Pkg.Name() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl;*/
 
+   if (Debug == true)
+   {
+      for (int j = 0; j != Depth; j++) clog << ' ';
+      clog << "Leave " << Pkg.Name() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl;
+   }
+   
    return true;
 }
                                                                        /*}}}*/
@@ -478,7 +600,8 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
       {
         /* Reverse depenanices are only interested in conflicts,
            predepend breakage is ignored here */
-        if (D->Type != pkgCache::Dep::Conflicts)
+        if (D->Type != pkgCache::Dep::Conflicts && 
+            D->Type != pkgCache::Dep::Obsoletes)
            continue;
 
         // Duplication elimination, consider only the current version
@@ -499,7 +622,9 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
       {
         /* Forward critical dependencies MUST be correct before the 
            package can be unpacked. */
-        if (D->Type != pkgCache::Dep::Conflicts && D->Type != pkgCache::Dep::PreDepends)
+        if (D->Type != pkgCache::Dep::Conflicts &&
+            D->Type != pkgCache::Dep::Obsoletes &&
+            D->Type != pkgCache::Dep::PreDepends)
            continue;
                                 
         /* We wish to check if the dep is okay in the now state of the
@@ -527,8 +652,8 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D)
         DepFunc Old = Primary;
         bool Res = false;
         if (D->Type == pkgCache::Dep::PreDepends)
-           Primary = &DepUnPackPreD;
-        Res = VisitProvides(D);
+           Primary = &pkgOrderList::DepUnPackPreD;
+        Res = VisitProvides(D,true);
         Primary = Old;
         if (Res == false)
            return false;
@@ -574,7 +699,7 @@ bool pkgOrderList::DepUnPackPreD(DepIterator D)
         continue;
       }
       
-      if (VisitProvides(D) == false)
+      if (VisitProvides(D,true) == false)
         return false;
    }   
    return true;
@@ -607,7 +732,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D)
         else
            continue;
       }
-
+      
       /* We wish to check if the dep is okay in the now state of the
          target package against the install state of this package. */
       if (CheckDep(D) == true)
@@ -617,7 +742,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D)
         if (IsFlag(D.TargetPkg(),AddPending) == false)
            continue;
       }
-      
+
       // This is the loop detection
       if (IsFlag(D.TargetPkg(),Added) == true || 
          IsFlag(D.TargetPkg(),AddPending) == true)
@@ -627,7 +752,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D)
         continue;
       }
       
-      if (VisitProvides(D) == false)
+      if (VisitProvides(D,true) == false)
         return false;
    }   
    return true;
@@ -663,12 +788,16 @@ bool pkgOrderList::DepUnPackDep(DepIterator D)
            if (CheckDep(D) == true)
               continue;
            
+           // Skip over missing files
+           if (IsMissing(D.ParentPkg()) == true)
+              continue;
+           
            if (VisitNode(D.ParentPkg()) == false)
               return false;
         }
         else
            if (D->Type == pkgCache::Dep::Depends)
-              if (VisitProvides(D) == false)
+              if (VisitProvides(D,false) == false)
                  return false;
       }
    return true;
@@ -689,7 +818,7 @@ bool pkgOrderList::DepConfigure(DepIterator D)
    
    for (; D.end() == false; D++)
       if (D->Type == pkgCache::Dep::Depends)
-        if (VisitProvides(D) == false)
+        if (VisitProvides(D,false) == false)
            return false;
    return true;
 }
@@ -734,6 +863,10 @@ bool pkgOrderList::DepRemove(DepIterator D)
            continue;
         }
 
+        // Skip over missing files
+        if (IsMissing(D.ParentPkg()) == true)
+           continue;
+        
         if (VisitNode(D.ParentPkg()) == false)
            return false;
       }
@@ -772,7 +905,7 @@ bool pkgOrderList::AddLoop(DepIterator D)
 /* */
 void pkgOrderList::WipeFlags(unsigned long F)
 {
-   unsigned long Size = Cache.HeaderP->PackageCount;
+   unsigned long Size = Cache.Head().PackageCount;
    for (unsigned long I = 0; I != Size; I++)
       Flags[I] &= ~F;
 }
@@ -786,7 +919,8 @@ void pkgOrderList::WipeFlags(unsigned long F)
    this fails to produce a suitable result. */
 bool pkgOrderList::CheckDep(DepIterator D)
 {
-   Version **List = D.AllTargets();
+   SPtrArray<Version *> List = D.AllTargets();
+   bool Hit = false;
    for (Version **I = List; *I != 0; I++)
    {
       VerIterator Ver(Cache,*I);
@@ -797,8 +931,8 @@ bool pkgOrderList::CheckDep(DepIterator D)
                 way ordering works Added means the package will be unpacked
                 before this one and AddPending means after. It is therefore
                 correct to ignore AddPending in all cases, but that exposes
-                reverse-ordering loops which should be ignore. */
-      if (IsFlag(Pkg,Added) == true || 
+                reverse-ordering loops which should be ignored. */
+      if (IsFlag(Pkg,Added) == true ||
          (IsFlag(Pkg,AddPending) == true && D.Reverse() == true))
       {
         if (Cache[Pkg].InstallVer != *I)
@@ -809,20 +943,41 @@ bool pkgOrderList::CheckDep(DepIterator D)
             Pkg.State() != PkgIterator::NeedsNothing)
            continue;
       
-      delete [] List;
-      
       /* Conflicts requires that all versions are not present, depends
          just needs one */
-      if (D->Type != pkgCache::Dep::Conflicts)
+      if (D->Type != pkgCache::Dep::Conflicts && 
+         D->Type != pkgCache::Dep::Obsoletes)
+      {
+        /* Try to find something that does not have the after flag set
+           if at all possible */
+        if (IsFlag(Pkg,After) == true)
+        {
+           Hit = true;
+           continue;
+        }
+      
         return true;
+      }
       else
+      {
+        if (IsFlag(Pkg,After) == true)
+           Flag(D.ParentPkg(),After);
+        
         return false;
+      }      
    }
-   delete [] List;
+
+   // We found a hit, but it had the after flag set
+   if (Hit == true && D->Type == pkgCache::Dep::PreDepends)
+   {
+      Flag(D.ParentPkg(),After);
+      return true;
+   }
+   
    /* Conflicts requires that all versions are not present, depends
       just needs one */
-   if (D->Type == pkgCache::Dep::Conflicts)
+   if (D->Type == pkgCache::Dep::Conflicts ||
+       D->Type == pkgCache::Dep::Obsoletes)
       return true;
    return false;
 }