]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcache.cc
add volatile sources support in libapt-pkg
[apt.git] / apt-pkg / pkgcache.cc
index 6c12b4581eefaf5f664ddfde6c03c2b700bceff5..e8c95738e9673848ce6d27c932449a9195234bea 100644 (file)
@@ -8,7 +8,7 @@
    Please see doc/apt-pkg/cache.sgml for a more detailed description of 
    this format. Also be sure to keep that file up-to-date!!
    
-   This is the general utility functions for cache managment. They provide
+   This is the general utility functions for cache management. They provide
    a complete set of accessor functions for the cache. The cacheiterators
    header contains the STL-like iterators that can be used to easially
    navigate the cache as well as seemlessly dereference the mmap'd 
@@ -20,6 +20,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include<config.h>
+
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/mmap.h>
 #include <apt-pkg/macros.h>
 
-#include <apti18n.h>
-    
+#include <stddef.h>
+#include <string.h>
+#include <ostream>
+#include <vector>
 #include <string>
 #include <sys/stat.h>
-#include <unistd.h>
 
-#include <ctype.h>
+#include <apti18n.h>
                                                                        /*}}}*/
 
 using std::string;
@@ -46,44 +50,52 @@ using std::string;
 /* Simply initialize the header */
 pkgCache::Header::Header()
 {
-   Signature = 0x98FE76DC;
-   
+#define APT_HEADER_SET(X,Y) X = Y; static_assert(std::numeric_limits<decltype(X)>::max() > Y, "Size violation detected in pkgCache::Header")
+   APT_HEADER_SET(Signature, 0x98FE76DC);
+
    /* Whenever the structures change the major version should be bumped,
       whenever the generator changes the minor version should be bumped. */
-   MajorVersion = 8;
-   MinorVersion = 0;
-   Dirty = false;
-   
-   HeaderSz = sizeof(pkgCache::Header);
-   GroupSz = sizeof(pkgCache::Group);
-   PackageSz = sizeof(pkgCache::Package);
-   PackageFileSz = sizeof(pkgCache::PackageFile);
-   VersionSz = sizeof(pkgCache::Version);
-   DescriptionSz = sizeof(pkgCache::Description);
-   DependencySz = sizeof(pkgCache::Dependency);
-   ProvidesSz = sizeof(pkgCache::Provides);
-   VerFileSz = sizeof(pkgCache::VerFile);
-   DescFileSz = sizeof(pkgCache::DescFile);
-   
+   APT_HEADER_SET(MajorVersion, 10);
+   APT_HEADER_SET(MinorVersion, 0);
+   APT_HEADER_SET(Dirty, false);
+
+   APT_HEADER_SET(HeaderSz, sizeof(pkgCache::Header));
+   APT_HEADER_SET(GroupSz, sizeof(pkgCache::Group));
+   APT_HEADER_SET(PackageSz, sizeof(pkgCache::Package));
+   APT_HEADER_SET(ReleaseFileSz, sizeof(pkgCache::ReleaseFile));
+   APT_HEADER_SET(PackageFileSz, sizeof(pkgCache::PackageFile));
+   APT_HEADER_SET(VersionSz, sizeof(pkgCache::Version));
+   APT_HEADER_SET(DescriptionSz, sizeof(pkgCache::Description));
+   APT_HEADER_SET(DependencySz, sizeof(pkgCache::Dependency));
+   APT_HEADER_SET(DependencyDataSz, sizeof(pkgCache::DependencyData));
+   APT_HEADER_SET(ProvidesSz, sizeof(pkgCache::Provides));
+   APT_HEADER_SET(VerFileSz, sizeof(pkgCache::VerFile));
+   APT_HEADER_SET(DescFileSz, sizeof(pkgCache::DescFile));
+#undef APT_HEADER_SET
+
    GroupCount = 0;
    PackageCount = 0;
    VersionCount = 0;
    DescriptionCount = 0;
    DependsCount = 0;
+   DependsDataCount = 0;
+   ReleaseFileCount = 0;
    PackageFileCount = 0;
    VerFileCount = 0;
    DescFileCount = 0;
    ProvidesCount = 0;
    MaxVerFileSize = 0;
    MaxDescFileSize = 0;
-   
+
    FileList = 0;
-   StringList = 0;
+   RlsFileList = 0;
    VerSysName = 0;
    Architecture = 0;
-   memset(PkgHashTable,0,sizeof(PkgHashTable));
-   memset(GrpHashTable,0,sizeof(GrpHashTable));
+   SetArchitectures(0);
+   SetHashTableSize(_config->FindI("APT::Cache-HashTableSize", 10 * 1048));
    memset(Pools,0,sizeof(Pools));
+
+   CacheFileSize = 0;
 }
                                                                        /*}}}*/
 // Cache::Header::CheckSizes - Check if the two headers have same *sz  /*{{{*/
@@ -94,10 +106,12 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
    if (HeaderSz == Against.HeaderSz &&
        GroupSz == Against.GroupSz &&
        PackageSz == Against.PackageSz &&
+       ReleaseFileSz == Against.ReleaseFileSz &&
        PackageFileSz == Against.PackageFileSz &&
        VersionSz == Against.VersionSz &&
        DescriptionSz == Against.DescriptionSz &&
        DependencySz == Against.DependencySz &&
+       DependencyDataSz == Against.DependencyDataSz &&
        VerFileSz == Against.VerFileSz &&
        DescFileSz == Against.DescFileSz &&
        ProvidesSz == Against.ProvidesSz)
@@ -109,7 +123,8 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
 // Cache::pkgCache - Constructor                                       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map)
+APT_IGNORE_DEPRECATED_PUSH
+pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), d(NULL)
 {
    // call getArchitectures() with cached=false to ensure that the 
    // architectures cache is re-evaulated. this is needed in cases
@@ -118,6 +133,7 @@ pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map)
    if (DoMap == true)
       ReMap();
 }
+APT_IGNORE_DEPRECATED_POP
                                                                        /*}}}*/
 // Cache::ReMap - Reopen the cache file                                        /*{{{*/
 // ---------------------------------------------------------------------
@@ -130,12 +146,13 @@ bool pkgCache::ReMap(bool const &Errorchecks)
    PkgP = (Package *)Map.Data();
    VerFileP = (VerFile *)Map.Data();
    DescFileP = (DescFile *)Map.Data();
+   RlsFileP = (ReleaseFile *)Map.Data();
    PkgFileP = (PackageFile *)Map.Data();
    VerP = (Version *)Map.Data();
    DescP = (Description *)Map.Data();
    ProvideP = (Provides *)Map.Data();
    DepP = (Dependency *)Map.Data();
-   StringItemP = (StringItem *)Map.Data();
+   DepDataP = (DependencyData *)Map.Data();
    StrP = (char *)Map.Data();
 
    if (Errorchecks == false)
@@ -155,15 +172,26 @@ bool pkgCache::ReMap(bool const &Errorchecks)
        HeaderP->CheckSizes(DefHeader) == false)
       return _error->Error(_("The package cache file is an incompatible version"));
 
+   if (Map.Size() < HeaderP->CacheFileSize)
+      return _error->Error(_("The package cache file is corrupted, it is too small"));
+
+   if (HeaderP->VerSysName == 0 || HeaderP->Architecture == 0 || HeaderP->GetArchitectures() == 0)
+      return _error->Error(_("The package cache file is corrupted"));
+
    // Locate our VS..
-   if (HeaderP->VerSysName == 0 ||
-       (VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0)
+   if ((VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0)
       return _error->Error(_("This APT does not support the versioning system '%s'"),StrP + HeaderP->VerSysName);
 
-   // Chcek the arhcitecture
-   if (HeaderP->Architecture == 0 ||
-       _config->Find("APT::Architecture") != StrP + HeaderP->Architecture)
-      return _error->Error(_("The package cache was built for a different architecture"));
+   // Check the architecture
+   std::vector<std::string> archs = APT::Configuration::getArchitectures();
+   std::vector<std::string>::const_iterator a = archs.begin();
+   std::string list = *a;
+   for (++a; a != archs.end(); ++a)
+      list.append(",").append(*a);
+   if (_config->Find("APT::Architecture") != StrP + HeaderP->Architecture ||
+        list != StrP + HeaderP->GetArchitectures())
+      return _error->Error(_("The package cache was built for different architectures: %s vs %s"), StrP + HeaderP->GetArchitectures(), list.c_str());
+
    return true;
 }
                                                                        /*}}}*/
@@ -172,22 +200,21 @@ bool pkgCache::ReMap(bool const &Errorchecks)
 /* This is used to generate the hash entries for the HashTable. With my
    package list from bo this function gets 94% table usage on a 512 item
    table (480 used items) */
-unsigned long pkgCache::sHash(const string &Str) const
+map_id_t pkgCache::sHash(const string &Str) const
 {
    unsigned long Hash = 0;
-   for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
-      Hash = 5*Hash + tolower_ascii(*I);
-   return Hash % _count(HeaderP->PkgHashTable);
+   for (string::const_iterator I = Str.begin(); I != Str.end(); ++I)
+      Hash = 41 * Hash + tolower_ascii(*I);
+   return Hash % HeaderP->GetHashTableSize();
 }
 
-unsigned long pkgCache::sHash(const char *Str) const
+map_id_t pkgCache::sHash(const char *Str) const
 {
-   unsigned long Hash = 0;
-   for (const char *I = Str; *I != 0; I++)
-      Hash = 5*Hash + tolower_ascii(*I);
-   return Hash % _count(HeaderP->PkgHashTable);
+   unsigned long Hash = tolower_ascii(*Str);
+   for (const char *I = Str + 1; *I != 0; ++I)
+      Hash = 41 * Hash + tolower_ascii(*I);
+   return Hash % HeaderP->GetHashTableSize();
 }
-
                                                                        /*}}}*/
 // Cache::SingleArchFindPkg - Locate a package by name                 /*{{{*/
 // ---------------------------------------------------------------------
@@ -197,12 +224,14 @@ unsigned long pkgCache::sHash(const char *Str) const
 pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
 {
    // Look at the hash bucket
-   Package *Pkg = PkgP + HeaderP->PkgHashTable[Hash(Name)];
+   Package *Pkg = PkgP + HeaderP->PkgHashTableP()[Hash(Name)];
    for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
    {
-      if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] &&
-          stringcasecmp(Name,StrP + Pkg->Name) == 0)
-         return PkgIterator(*this,Pkg);
+      int const cmp = strcmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name);
+      if (cmp == 0)
+        return PkgIterator(*this, Pkg);
+      else if (cmp < 0)
+        break;
    }
    return PkgIterator(*this,0);
 }
@@ -213,12 +242,7 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
        size_t const found = Name.find(':');
        if (found == string::npos)
-       {
-               if (MultiArchCache() == false)
-                       return SingleArchFindPkg(Name);
-               else
-                       return FindPkg(Name, "native");
-       }
+          return FindPkg(Name, "native");
        string const Arch = Name.substr(found+1);
        /* Beware: This is specialcased to handle pkg:any in dependencies as
           these are linked to virtual pkg:any named packages with all archs.
@@ -232,13 +256,6 @@ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) {
-       if (MultiArchCache() == false) {
-               if (Arch == "native" || Arch == "all" || Arch == "any" ||
-                   Arch == NativeArch())
-                       return SingleArchFindPkg(Name);
-               else
-                       return PkgIterator(*this,0);
-       }
        /* We make a detour via the GrpIterator here as
           on a multi-arch environment a group is easier to
           find than a package (less entries in the buckets) */
@@ -257,11 +274,13 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) {
                return GrpIterator(*this,0);
 
        // Look at the hash bucket for the group
-       Group *Grp = GrpP + HeaderP->GrpHashTable[sHash(Name)];
+       Group *Grp = GrpP + HeaderP->GrpHashTableP()[sHash(Name)];
        for (; Grp != GrpP; Grp = GrpP + Grp->Next) {
-               if (Grp->Name != 0 && StrP[Grp->Name] == Name[0] &&
-                   stringcasecmp(Name, StrP + Grp->Name) == 0)
+               int const cmp = strcmp(Name.c_str(), StrP + Grp->Name);
+               if (cmp == 0)
                        return GrpIterator(*this, Grp);
+               else if (cmp < 0)
+                       break;
        }
 
        return GrpIterator(*this,0);
@@ -273,22 +292,22 @@ pkgCache::GrpIterator pkgCache::FindGrp(const string &Name) {
    type in the weird debian style.. */
 const char *pkgCache::CompTypeDeb(unsigned char Comp)
 {
-   const char *Ops[] = {"","<=",">=","<<",">>","=","!="};
-   if ((unsigned)(Comp & 0xF) < 7)
-      return Ops[Comp & 0xF];
-   return "";   
+   const char * const Ops[] = {"","<=",">=","<<",">>","=","!="};
+   if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0])))
+      return "";
+   return Ops[Comp & 0xF];
 }
                                                                        /*}}}*/
 // Cache::CompType - Return a string describing the compare type       /*{{{*/
 // ---------------------------------------------------------------------
-/* This returns a string representation of the dependency compare 
+/* This returns a string representation of the dependency compare
    type */
 const char *pkgCache::CompType(unsigned char Comp)
 {
-   const char *Ops[] = {"","<=",">=","<",">","=","!="};
-   if ((unsigned)(Comp & 0xF) < 7)
-      return Ops[Comp & 0xF];
-   return "";   
+   const char * const Ops[] = {"","<=",">=","<",">","=","!="};
+   if (unlikely((unsigned)(Comp & 0xF) >= sizeof(Ops)/sizeof(Ops[0])))
+      return "";
+   return Ops[Comp & 0xF];
 }
                                                                        /*}}}*/
 // Cache::DepType - Return a string describing the dep type            /*{{{*/
@@ -334,19 +353,15 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const {
           last one we check, so we do it now. */
        if (Arch == "native" || Arch == myArch || Arch == "all") {
                pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
-               if (strcasecmp(myArch, Owner->StrP + Pkg->Arch) == 0)
+               if (strcmp(myArch, Owner->StrP + Pkg->Arch) == 0)
                        return PkgIterator(*Owner, Pkg);
                Arch = myArch;
        }
 
-       /* Iterate over the list to find the matching arch
-          unfortunately this list includes "package noise"
-          (= different packages with same calculated hash),
-          so we need to check the name also */
+       // Iterate over the list to find the matching arch
        for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP;
             Pkg = Owner->PkgP + Pkg->NextPackage) {
-               if (S->Name == Pkg->Name &&
-                   stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0)
+               if (stringcmp(Arch, Owner->StrP + Pkg->Arch) == 0)
                        return PkgIterator(*Owner, Pkg);
                if ((Owner->PkgP + S->LastPackage) == Pkg)
                        break;
@@ -370,6 +385,10 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg(bool const &Prefer
                if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0))
                        return Pkg;
        }
+       // packages without an architecture
+       Pkg = FindPkg("none");
+       if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0))
+               return Pkg;
 
        if (PreferNonVirtual == true)
                return FindPreferredPkg(false);
@@ -392,39 +411,53 @@ pkgCache::PkgIterator pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator const
        return PkgIterator(*Owner, Owner->PkgP + LastPkg->NextPackage);
 }
                                                                        /*}}}*/
-// GrpIterator::operator ++ - Postfix incr                             /*{{{*/
+// GrpIterator::operator++ - Prefix incr                               /*{{{*/
 // ---------------------------------------------------------------------
 /* This will advance to the next logical group in the hash table. */
-void pkgCache::GrpIterator::operator ++(int) 
+pkgCache::GrpIterator& pkgCache::GrpIterator::operator++()
 {
    // Follow the current links
    if (S != Owner->GrpP)
       S = Owner->GrpP + S->Next;
 
    // Follow the hash table
-   while (S == Owner->GrpP && (HashIndex+1) < (signed)_count(Owner->HeaderP->GrpHashTable))
+   while (S == Owner->GrpP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize())
    {
-      HashIndex++;
-      S = Owner->GrpP + Owner->HeaderP->GrpHashTable[HashIndex];
+      ++HashIndex;
+      S = Owner->GrpP + Owner->HeaderP->GrpHashTableP()[HashIndex];
    }
-};
+   return *this;
+}
                                                                        /*}}}*/
-// PkgIterator::operator ++ - Postfix incr                             /*{{{*/
+// PkgIterator::operator++ - Prefix incr                               /*{{{*/
 // ---------------------------------------------------------------------
 /* This will advance to the next logical package in the hash table. */
-void pkgCache::PkgIterator::operator ++(int) 
+pkgCache::PkgIterator& pkgCache::PkgIterator::operator++()
 {
    // Follow the current links
    if (S != Owner->PkgP)
       S = Owner->PkgP + S->NextPackage;
 
    // Follow the hash table
-   while (S == Owner->PkgP && (HashIndex+1) < (signed)_count(Owner->HeaderP->PkgHashTable))
+   while (S == Owner->PkgP && (HashIndex+1) < (signed)Owner->HeaderP->GetHashTableSize())
    {
-      HashIndex++;
-      S = Owner->PkgP + Owner->HeaderP->PkgHashTable[HashIndex];
+      ++HashIndex;
+      S = Owner->PkgP + Owner->HeaderP->PkgHashTableP()[HashIndex];
    }
-};
+   return *this;
+}
+                                                                       /*}}}*/
+pkgCache::DepIterator& pkgCache::DepIterator::operator++()             /*{{{*/
+{
+   if (S == Owner->DepP)
+      return *this;
+   S = Owner->DepP + (Type == DepVer ? S->NextDepends : S->NextRevDepends);
+   if (S == Owner->DepP)
+      S2 = Owner->DepDataP;
+   else
+      S2 = Owner->DepDataP + S->DependencyData;
+   return *this;
+}
                                                                        /*}}}*/
 // PkgIterator::State - Check the State of the package                 /*{{{*/
 // ---------------------------------------------------------------------
@@ -456,35 +489,35 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
 // ---------------------------------------------------------------------
 /* Return string representing of the candidate version. */
 const char *
-pkgCache::PkgIterator::CandVersion() const 
+pkgCache::PkgIterator::CandVersion() const
 {
   //TargetVer is empty, so don't use it.
   VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this);
   if (version.IsGood())
     return version.VerStr();
   return 0;
-};
+}
                                                                        /*}}}*/
 // PkgIterator::CurVersion - Returns the current version string                /*{{{*/
 // ---------------------------------------------------------------------
 /* Return string representing of the current version. */
 const char *
-pkgCache::PkgIterator::CurVersion() const 
+pkgCache::PkgIterator::CurVersion() const
 {
   VerIterator version = CurrentVer();
   if (version.IsGood())
     return CurrentVer().VerStr();
   return 0;
-};
+}
                                                                        /*}}}*/
 // ostream operator to handle string representation of a package       /*{{{*/
 // ---------------------------------------------------------------------
 /* Output name < cur.rent.version -> candid.ate.version | new.est.version > (section)
-   Note that the characters <|>() are all literal above. Versions will be ommited
+   Note that the characters <|>() are all literal above. Versions will be omitted
    if they provide no new information (e.g. there is no newer version than candidate)
    If no version and/or section can be found "none" is used. */
 std::ostream& 
-operator<<(ostream& out, pkgCache::PkgIterator Pkg) 
+operator<<(std::ostream& out, pkgCache::PkgIterator Pkg) 
 {
    if (Pkg.end() == true)
       return out << "invalid package";
@@ -498,7 +531,10 @@ operator<<(ostream& out, pkgCache::PkgIterator Pkg)
       out << " -> " << candidate;
    if ( newest != "none" && candidate != newest)
       out << " | " << newest;
-   out << " > ( " << string(Pkg.Section()==0?"none":Pkg.Section()) << " )";
+   if (Pkg->VersionList == 0)
+      out << " > ( none )";
+   else
+      out << " > ( " << string(Pkg.VersionList().Section()==0?"unknown":Pkg.VersionList().Section()) << " )";
    return out;
 }
                                                                        /*}}}*/
@@ -521,11 +557,9 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
    conflicts (including dpkg's Breaks fields). */
 bool pkgCache::DepIterator::IsCritical() const
 {
-   if (S->Type == pkgCache::Dep::Conflicts ||
-       S->Type == pkgCache::Dep::DpkgBreaks ||
-       S->Type == pkgCache::Dep::Obsoletes ||
-       S->Type == pkgCache::Dep::Depends ||
-       S->Type == pkgCache::Dep::PreDepends)
+   if (IsNegative() == true ||
+       S2->Type == pkgCache::Dep::Depends ||
+       S2->Type == pkgCache::Dep::PreDepends)
       return true;
    return false;
 }
@@ -536,9 +570,9 @@ bool pkgCache::DepIterator::IsCritical() const
    are negative like Conflicts which can and should be handled differently */
 bool pkgCache::DepIterator::IsNegative() const
 {
-   return S->Type == Dep::DpkgBreaks ||
-         S->Type == Dep::Conflicts ||
-         S->Type == Dep::Obsoletes;
+   return S2->Type == Dep::DpkgBreaks ||
+         S2->Type == Dep::Conflicts ||
+         S2->Type == Dep::Obsoletes;
 }
                                                                        /*}}}*/
 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides        /*{{{*/
@@ -571,7 +605,7 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const
       virtual package libc-dev which is provided by libc5-dev and libc6-dev
       we must ignore libc5-dev when considering the provides list. */ 
    PrvIterator PStart = Result.ProvidesList();
-   for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); PStart++);
+   for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); ++PStart);
 
    // Nothing but indirect self provides
    if (PStart.end() == true)
@@ -579,7 +613,7 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const
    
    // Check for single packages in the provides list
    PrvIterator P = PStart;
-   for (; P.end() != true; P++)
+   for (; P.end() != true; ++P)
    {
       // Skip over self provides
       if (P.OwnerPkg() == ParentPkg())
@@ -613,34 +647,26 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
       PkgIterator DPkg = TargetPkg();
 
       // Walk along the actual package providing versions
-      for (VerIterator I = DPkg.VersionList(); I.end() == false; I++)
+      for (VerIterator I = DPkg.VersionList(); I.end() == false; ++I)
       {
-        if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
+        if (IsIgnorable(I.ParentPkg()) == true)
            continue;
-
-        if ((S->Type == pkgCache::Dep::Conflicts ||
-             S->Type == pkgCache::Dep::DpkgBreaks ||
-             S->Type == pkgCache::Dep::Obsoletes) &&
-            ParentPkg() == I.ParentPkg())
+        if (IsSatisfied(I) == false)
            continue;
-        
+
         Size++;
         if (Res != 0)
            *End++ = I;
       }
       
       // Follow all provides
-      for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; I++)
+      for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; ++I)
       {
-        if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
+        if (IsIgnorable(I) == true)
            continue;
-        
-        if ((S->Type == pkgCache::Dep::Conflicts ||
-             S->Type == pkgCache::Dep::DpkgBreaks ||
-             S->Type == pkgCache::Dep::Obsoletes) &&
-            ParentPkg() == I.OwnerPkg())
+        if (IsSatisfied(I) == false)
            continue;
-        
+
         Size++;
         if (Res != 0)
            *End++ = I.OwnerVer();
@@ -675,17 +701,81 @@ void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End)
    End = *this;
    for (bool LastOR = true; end() == false && LastOR == true;)
    {
-      LastOR = (S->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
-      (*this)++;
+      LastOR = (S2->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
+      ++(*this);
       if (LastOR == true)
         End = (*this);
    }
 }
                                                                        /*}}}*/
+// DepIterator::IsIgnorable - should this packag/providr be ignored?   /*{{{*/
+// ---------------------------------------------------------------------
+/* Deps like self-conflicts should be ignored as well as implicit conflicts
+   on virtual packages. */
+bool pkgCache::DepIterator::IsIgnorable(PkgIterator const &PT) const
+{
+   if (IsNegative() == false)
+      return false;
+
+   pkgCache::PkgIterator const PP = ParentPkg();
+   if (PP->Group != PT->Group)
+      return false;
+   // self-conflict
+   if (PP == PT)
+      return true;
+   pkgCache::VerIterator const PV = ParentVer();
+   // ignore group-conflict on a M-A:same package - but not our implicit dependencies
+   // so that we can have M-A:same packages conflicting with their own real name
+   if ((PV->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+      return IsMultiArchImplicit() == false;
+
+   return false;
+}
+bool pkgCache::DepIterator::IsIgnorable(PrvIterator const &Prv) const
+{
+   if (IsNegative() == false)
+      return false;
+
+   PkgIterator const Pkg = ParentPkg();
+   /* Provides may never be applied against the same package (or group)
+      if it is a conflicts. See the comment above. */
+   if (Prv.OwnerPkg()->Group == Pkg->Group)
+      return true;
+   // Implicit group-conflicts should not be applied on providers of other groups
+   if (IsMultiArchImplicit() && Prv.OwnerPkg()->Group != Pkg->Group)
+      return true;
+
+   return false;
+}
+                                                                       /*}}}*/
+// DepIterator::IsSatisfied - check if a version satisfied the dependency /*{{{*/
+bool pkgCache::DepIterator::IsSatisfied(VerIterator const &Ver) const
+{
+   return Owner->VS->CheckDep(Ver.VerStr(),S2->CompareOp,TargetVer());
+}
+bool pkgCache::DepIterator::IsSatisfied(PrvIterator const &Prv) const
+{
+   return Owner->VS->CheckDep(Prv.ProvideVersion(),S2->CompareOp,TargetVer());
+}
+                                                                       /*}}}*/
+// DepIterator::IsImplicit - added by the cache generation             /*{{{*/
+bool pkgCache::DepIterator::IsImplicit() const
+{
+   if (IsMultiArchImplicit() == true)
+      return true;
+   if (IsNegative() || S2->Type == pkgCache::Dep::Replaces)
+   {
+      if ((S2->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific &&
+           strcmp(ParentPkg().Arch(), TargetPkg().Arch()) != 0)
+        return true;
+   }
+   return false;
+}
+                                                                       /*}}}*/
 // ostream operator to handle string representation of a dependecy     /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-std::ostream& operator<<(ostream& out, pkgCache::DepIterator D)
+std::ostream& operator<<(std::ostream& out, pkgCache::DepIterator D)
 {
    if (D.end() == true)
       return out << "invalid dependency";
@@ -723,7 +813,7 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const
    /* Start at A and look for B. If B is found then A > B otherwise
       B was before A so A < B */
    VerIterator I = *this;
-   for (;I.end() == false; I++)
+   for (;I.end() == false; ++I)
       if (I == B)
         return 1;
    return -1;
@@ -732,11 +822,11 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const
 // VerIterator::Downloadable - Checks if the version is downloadable   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgCache::VerIterator::Downloadable() const
+APT_PURE bool pkgCache::VerIterator::Downloadable() const
 {
    VerFileIterator Files = FileList();
-   for (; Files.end() == false; Files++)
-      if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource)
+   for (; Files.end() == false; ++Files)
+      if (Files.File().Flagged(pkgCache::Flag::NotSource) == false)
         return true;
    return false;
 }
@@ -745,19 +835,16 @@ bool pkgCache::VerIterator::Downloadable() const
 // ---------------------------------------------------------------------
 /* This checks to see if any of the versions files are not NotAutomatic. 
    True if this version is selectable for automatic installation. */
-bool pkgCache::VerIterator::Automatic() const
+APT_PURE bool pkgCache::VerIterator::Automatic() const
 {
    VerFileIterator Files = FileList();
-   for (; Files.end() == false; Files++)
+   for (; Files.end() == false; ++Files)
       // Do not check ButAutomaticUpgrades here as it is kind of automatic…
-      if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic)
+      if (Files.File().Flagged(pkgCache::Flag::NotAutomatic) == false)
         return true;
    return false;
 }
                                                                        /*}}}*/
-// VerIterator::Pseudo - deprecated no-op method                       /*{{{*/
-bool pkgCache::VerIterator::Pseudo() const { return false; }
-                                                                       /*}}}*/
 // VerIterator::NewestFile - Return the newest file version relation   /*{{{*/
 // ---------------------------------------------------------------------
 /* This looks at the version numbers associated with all of the sources
@@ -766,7 +853,7 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const
 {
    VerFileIterator Files = FileList();
    VerFileIterator Highest = Files;
-   for (; Files.end() == false; Files++)
+   for (; Files.end() == false; ++Files)
    {
       if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0)
         Highest = Files;
@@ -783,30 +870,30 @@ string pkgCache::VerIterator::RelStr() const
 {
    bool First = true;
    string Res;
-   for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; I++)
+   for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; ++I)
    {
       // Do not print 'not source' entries'
-      pkgCache::PkgFileIterator File = I.File();
-      if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
+      pkgCache::PkgFileIterator const File = I.File();
+      if (File.Flagged(pkgCache::Flag::NotSource))
         continue;
 
       // See if we have already printed this out..
       bool Seen = false;
-      for (pkgCache::VerFileIterator J = this->FileList(); I != J; J++)
+      for (pkgCache::VerFileIterator J = this->FileList(); I != J; ++J)
       {
-        pkgCache::PkgFileIterator File2 = J.File();
-        if (File2->Label == 0 || File->Label == 0)
+        pkgCache::PkgFileIterator const File2 = J.File();
+        if (File2.Label() == 0 || File.Label() == 0)
            continue;
 
         if (strcmp(File.Label(),File2.Label()) != 0)
            continue;
         
-        if (File2->Version == File->Version)
+        if (File2.Version() == File.Version())
         {
            Seen = true;
            break;
         }
-        if (File2->Version == 0 || File->Version == 0)
+        if (File2.Version() == 0 || File.Version() == 0)
            break;
         if (strcmp(File.Version(),File2.Version()) == 0)
            Seen = true;
@@ -820,12 +907,12 @@ string pkgCache::VerIterator::RelStr() const
       else
         First = false;
       
-      if (File->Label != 0)
+      if (File.Label() != 0)
         Res = Res + File.Label() + ':';
 
-      if (File->Archive != 0)
+      if (File.Archive() != 0)
       {
-        if (File->Version == 0)
+        if (File.Version() == 0)
            Res += File.Archive();
         else
            Res = Res + File.Version() + '/' +  File.Archive();
@@ -833,7 +920,7 @@ string pkgCache::VerIterator::RelStr() const
       else
       {
         // No release file, print the host name that this came from
-        if (File->Site == 0 || File.Site()[0] == 0)
+        if (File.Site() == 0 || File.Site()[0] == 0)
            Res += "localhost";
         else
            Res += File.Site();
@@ -844,12 +931,24 @@ string pkgCache::VerIterator::RelStr() const
    return Res;
 }
                                                                        /*}}}*/
-// PkgFileIterator::IsOk - Checks if the cache is in sync with the file        /*{{{*/
+// VerIterator::MultiArchType - string representing MultiArch flag     /*{{{*/
+const char * pkgCache::VerIterator::MultiArchType() const
+{
+   if ((S->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+      return "same";
+   else if ((S->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
+      return "foreign";
+   else if ((S->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
+      return "allowed";
+   return "none";
+}
+                                                                       /*}}}*/
+// RlsFileIterator::IsOk - Checks if the cache is in sync with the file        /*{{{*/
 // ---------------------------------------------------------------------
 /* This stats the file and compares its stats with the ones that were
-   stored during generation. Date checks should probably also be 
+   stored during generation. Date checks should probably also be
    included here. */
-bool pkgCache::PkgFileIterator::IsOk()
+bool pkgCache::RlsFileIterator::IsOk()
 {
    struct stat Buf;
    if (stat(FileName(),&Buf) != 0)
@@ -861,10 +960,8 @@ bool pkgCache::PkgFileIterator::IsOk()
    return true;
 }
                                                                        /*}}}*/
-// PkgFileIterator::RelStr - Return the release string                 /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string pkgCache::PkgFileIterator::RelStr()
+// RlsFileIterator::RelStr - Return the release string                 /*{{{*/
+string pkgCache::RlsFileIterator::RelStr()
 {
    string Res;
    if (Version() != 0)
@@ -877,8 +974,40 @@ string pkgCache::PkgFileIterator::RelStr()
       Res = Res + (Res.empty() == true?"n=":",n=")  + Codename();
    if (Label() != 0)
       Res = Res + (Res.empty() == true?"l=":",l=")  + Label();
-   if (Component() != 0)
-      Res = Res + (Res.empty() == true?"c=":",c=")  + Component();
+   return Res;
+}
+                                                                       /*}}}*/
+// PkgFileIterator::IsOk - Checks if the cache is in sync with the file        /*{{{*/
+// ---------------------------------------------------------------------
+/* This stats the file and compares its stats with the ones that were
+   stored during generation. Date checks should probably also be
+   included here. */
+bool pkgCache::PkgFileIterator::IsOk()
+{
+   struct stat Buf;
+   if (stat(FileName(),&Buf) != 0)
+      return false;
+
+   if (Buf.st_size != (signed)S->Size || Buf.st_mtime != S->mtime)
+      return false;
+
+   return true;
+}
+                                                                       /*}}}*/
+string pkgCache::PkgFileIterator::RelStr()                             /*{{{*/
+{
+   std::string Res;
+   if (ReleaseFile() == 0)
+   {
+      if (Component() != 0)
+        Res = Res + (Res.empty() == true?"a=":",a=")  + Component();
+   }
+   else
+   {
+      Res = ReleaseFile().RelStr();
+      if (Component() != 0)
+        Res = Res + (Res.empty() == true?"c=":",c=")  + Component();
+   }
    if (Architecture() != 0)
       Res = Res + (Res.empty() == true?"b=":",b=")  + Architecture();
    return Res;
@@ -886,22 +1015,33 @@ string pkgCache::PkgFileIterator::RelStr()
                                                                        /*}}}*/
 // VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/
 // ---------------------------------------------------------------------
-/* return a DescIter for the current locale or the default if none is 
+/* return a DescIter for the current locale or the default if none is
  * found
  */
 pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
 {
    std::vector<string> const lang = APT::Configuration::getLanguages();
    for (std::vector<string>::const_iterator l = lang.begin();
-       l != lang.end(); l++)
+       l != lang.end(); ++l)
    {
       pkgCache::DescIterator Desc = DescriptionList();
       for (; Desc.end() == false; ++Desc)
-        if (*l == Desc.LanguageCode() ||
-            (*l == "en" && strcmp(Desc.LanguageCode(),"") == 0))
+        if (*l == Desc.LanguageCode())
            break;
       if (Desc.end() == true)
-        continue;
+      {
+        if (*l == "en")
+        {
+           Desc = DescriptionList();
+           for (; Desc.end() == false; ++Desc)
+              if (strcmp(Desc.LanguageCode(), "") == 0)
+                 break;
+           if (Desc.end() == true)
+              continue;
+        }
+        else
+           continue;
+      }
       return Desc;
    }
    for (pkgCache::DescIterator Desc = DescriptionList();
@@ -909,6 +1049,8 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
       if (strcmp(Desc.LanguageCode(), "") == 0)
         return Desc;
    return DescriptionList();
-};
+}
 
                                                                        /*}}}*/
+
+pkgCache::~pkgCache() {}