]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcache.cc
releasing version 0.8.16~exp3
[apt.git] / apt-pkg / pkgcache.cc
index 324445fa70d1018fe61f39c58ba6c9bac1d89672..951caeb7822dae9fac1fc9f575a40b820225dec0 100644 (file)
@@ -211,12 +211,18 @@ pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
 // ---------------------------------------------------------------------
 /* Returns 0 on error, pointer to the package otherwise */
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
-       if (MultiArchCache() == false)
-               return SingleArchFindPkg(Name);
        size_t const found = Name.find(':');
        if (found == string::npos)
        size_t const found = Name.find(':');
        if (found == string::npos)
-               return FindPkg(Name, "native");
+       {
+               if (MultiArchCache() == false)
+                       return SingleArchFindPkg(Name);
+               else
+                       return FindPkg(Name, "native");
+       }
        string const Arch = Name.substr(found+1);
        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.
+          If you want any arch from a given pkg, use FindPkg(pkg,arch) */
        if (Arch == "any")
                return FindPkg(Name, "any");
        return FindPkg(Name.substr(0, found), Arch);
        if (Arch == "any")
                return FindPkg(Name, "any");
        return FindPkg(Name.substr(0, found), Arch);
@@ -228,7 +234,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) {
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) {
        if (MultiArchCache() == false) {
                if (Arch == "native" || Arch == "all" || Arch == "any" ||
 pkgCache::PkgIterator pkgCache::FindPkg(const string &Name, string const &Arch) {
        if (MultiArchCache() == false) {
                if (Arch == "native" || Arch == "all" || Arch == "any" ||
-                   Arch == _config->Find("APT::Architecture"))
+                   Arch == NativeArch())
                        return SingleArchFindPkg(Name);
                else
                        return PkgIterator(*this,0);
                        return SingleArchFindPkg(Name);
                else
                        return PkgIterator(*this,0);
@@ -317,22 +323,22 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) const {
        if (unlikely(IsGood() == false || S->FirstPackage == 0))
                return PkgIterator(*Owner, 0);
 
        if (unlikely(IsGood() == false || S->FirstPackage == 0))
                return PkgIterator(*Owner, 0);
 
-       static string const myArch = _config->Find("APT::Architecture");
+       /* If we accept any package we simply return the "first"
+          package in this group (the last one added). */
+       if (Arch == "any")
+               return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage);
+
+       char const* const myArch = Owner->NativeArch();
        /* Most of the time the package for our native architecture is
           the one we add at first to the cache, but this would be the
           last one we check, so we do it now. */
        /* Most of the time the package for our native architecture is
           the one we add at first to the cache, but this would be the
           last one we check, so we do it now. */
-       if (Arch == "native" || Arch == myArch) {
-               Arch = myArch;
+       if (Arch == "native" || Arch == myArch || Arch == "all") {
                pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
                pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
-               if (stringcasecmp(Arch, Owner->StrP + Pkg->Arch) == 0)
+               if (strcasecmp(myArch, Owner->StrP + Pkg->Arch) == 0)
                        return PkgIterator(*Owner, Pkg);
                        return PkgIterator(*Owner, Pkg);
+               Arch = myArch;
        }
 
        }
 
-       /* If we accept any package we simply return the "first"
-          package in this group (the last one added). */
-       if (Arch == "any")
-               return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage);
-
        /* Iterate over the list to find the matching arch
           unfortunately this list includes "package noise"
           (= different packages with same calculated hash),
        /* Iterate over the list to find the matching arch
           unfortunately this list includes "package noise"
           (= different packages with same calculated hash),
@@ -503,7 +509,8 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
 {
    string fullname = Name();
    if (Pretty == false ||
 {
    string fullname = Name();
    if (Pretty == false ||
-       (strcmp(Arch(), "all") != 0 && _config->Find("APT::Architecture") != Arch()))
+       (strcmp(Arch(), "all") != 0 &&
+       strcmp(Owner->NativeArch(), Arch()) != 0))
       return fullname.append(":").append(Arch());
    return fullname;
 }
       return fullname.append(":").append(Arch());
    return fullname;
 }
@@ -514,15 +521,24 @@ std::string pkgCache::PkgIterator::FullName(bool const &Pretty) const
    conflicts (including dpkg's Breaks fields). */
 bool pkgCache::DepIterator::IsCritical() 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 ||
+   if (IsNegative() == true ||
        S->Type == pkgCache::Dep::Depends ||
        S->Type == pkgCache::Dep::PreDepends)
       return true;
    return false;
 }
                                                                        /*}}}*/
        S->Type == pkgCache::Dep::Depends ||
        S->Type == pkgCache::Dep::PreDepends)
       return true;
    return false;
 }
                                                                        /*}}}*/
+// DepIterator::IsNegative - Returns true if the dep is a negative one /*{{{*/
+// ---------------------------------------------------------------------
+/* Some dependencies are positive like Depends and Recommends, others
+   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;
+}
+                                                                       /*}}}*/
 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides        /*{{{*/
 // ---------------------------------------------------------------------
 /* This intellegently looks at dep target packages and tries to figure
 // DepIterator::SmartTargetPkg - Resolve dep target pointers w/provides        /*{{{*/
 // ---------------------------------------------------------------------
 /* This intellegently looks at dep target packages and tries to figure
@@ -600,9 +616,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
         if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
            continue;
 
         if (Owner->VS->CheckDep(I.VerStr(),S->CompareOp,TargetVer()) == false)
            continue;
 
-        if ((S->Type == pkgCache::Dep::Conflicts ||
-             S->Type == pkgCache::Dep::DpkgBreaks ||
-             S->Type == pkgCache::Dep::Obsoletes) &&
+        if (IsNegative() == true &&
             ParentPkg() == I.ParentPkg())
            continue;
         
             ParentPkg() == I.ParentPkg())
            continue;
         
@@ -617,9 +631,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const
         if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
            continue;
         
         if (Owner->VS->CheckDep(I.ProvideVersion(),S->CompareOp,TargetVer()) == false)
            continue;
         
-        if ((S->Type == pkgCache::Dep::Conflicts ||
-             S->Type == pkgCache::Dep::DpkgBreaks ||
-             S->Type == pkgCache::Dep::Obsoletes) &&
+        if (IsNegative() == true &&
             ParentPkg() == I.OwnerPkg())
            continue;
         
             ParentPkg() == I.OwnerPkg())
            continue;
         
@@ -737,23 +749,6 @@ bool pkgCache::VerIterator::Automatic() const
    return false;
 }
                                                                        /*}}}*/
    return false;
 }
                                                                        /*}}}*/
-// VerIterator::Pseudo - Check if this version is a pseudo one         /*{{{*/
-// ---------------------------------------------------------------------
-/* Sometimes you have the need to express dependencies with versions
-   which doesn't really exist or exist multiply times for "different"
-   packages. We need these versions for dependency resolution but they
-   are a problem everytime we need to download/install something. */
-bool pkgCache::VerIterator::Pseudo() const
-{
-   if (S->MultiArch == pkgCache::Version::All &&
-          strcmp(Arch(true),"all") != 0)
-   {
-          GrpIterator const Grp = ParentPkg().Group();
-          return (Grp->LastPackage != Grp->FirstPackage);
-   }
-   return false;
-}
-                                                                       /*}}}*/
 // VerIterator::NewestFile - Return the newest file version relation   /*{{{*/
 // ---------------------------------------------------------------------
 /* This looks at the version numbers associated with all of the sources
 // VerIterator::NewestFile - Return the newest file version relation   /*{{{*/
 // ---------------------------------------------------------------------
 /* This looks at the version numbers associated with all of the sources
@@ -891,18 +886,19 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const
    for (std::vector<string>::const_iterator l = lang.begin();
        l != lang.end(); l++)
    {
    for (std::vector<string>::const_iterator l = lang.begin();
        l != lang.end(); l++)
    {
-      pkgCache::DescIterator DescDefault = DescriptionList();
-      pkgCache::DescIterator Desc = DescDefault;
-
-      for (; Desc.end() == false; Desc++)
+      pkgCache::DescIterator Desc = DescriptionList();
+      for (; Desc.end() == false; ++Desc)
         if (*l == Desc.LanguageCode() ||
             (*l == "en" && strcmp(Desc.LanguageCode(),"") == 0))
            break;
         if (*l == Desc.LanguageCode() ||
             (*l == "en" && strcmp(Desc.LanguageCode(),"") == 0))
            break;
-      if (Desc.end() == true) 
-        Desc = DescDefault;
+      if (Desc.end() == true)
+        continue;
       return Desc;
    }
       return Desc;
    }
-
+   for (pkgCache::DescIterator Desc = DescriptionList();
+       Desc.end() == false; ++Desc)
+      if (strcmp(Desc.LanguageCode(), "") == 0)
+        return Desc;
    return DescriptionList();
 };
 
    return DescriptionList();
 };