X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/762d7367f5f74f877ec75986e19fc9d46eef5164..259f688a29728604d7930662e9743619982706ab:/apt-pkg/policy.cc

diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index f9901bc9a..9b24c2ef1 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -121,6 +121,10 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg)
    signed Max = GetPriority(Pkg);
    pkgCache::VerIterator Pref = GetMatch(Pkg);
 
+   // Alternatives in case we can not find our package pin (Bug#512318).
+   signed MaxAlt = 0;
+   pkgCache::VerIterator PrefAlt;
+
    // no package = no candidate version
    if (Pkg.end() == true)
       return Pref;
@@ -159,6 +163,11 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg)
 	 {
 	    Pref = Ver;
 	    Max = Prio;
+	 }
+	 if (Prio > MaxAlt)
+	 {
+	    PrefAlt = Ver;
+	    MaxAlt = Prio;
 	 }	 
       }      
       
@@ -175,6 +184,11 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg)
 	    break;
       }            
    }
+   // If we do not find our candidate, use the one with the highest pin.
+   // This means that if there is a version available with pin > 0; there
+   // will always be a candidate (Closes: #512318)
+   if (!Pref.IsGood() && MaxAlt > 0)
+       Pref = PrefAlt;
    return Pref;
 }
 									/*}}}*/
@@ -187,35 +201,38 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg)
 void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name,
 			  string Data,signed short Priority)
 {
-   Pin *P = 0;
-   
    if (Name.empty() == true)
-      P = &*Defaults.insert(Defaults.end(),PkgPin());
-   else
    {
-      // Get a spot to put the pin
-      pkgCache::PkgIterator Pkg = Cache->FindPkg(Name);
-      if (Pkg.end() == true)
+      Pin *P = &*Defaults.insert(Defaults.end(),PkgPin());
+      P->Type = Type;
+      P->Priority = Priority;
+      P->Data = Data;
+      return;
+   }
+
+   // Get a spot to put the pin
+   pkgCache::GrpIterator Grp = Cache->FindGrp(Name);
+   for (pkgCache::PkgIterator Pkg = Grp.FindPkg("any");
+	Pkg.end() != true; Pkg = Grp.NextPkg(Pkg))
+   {
+      Pin *P = 0;
+      if (Pkg.end() == false)
+	 P = Pins + Pkg->ID;
+      else
       {
 	 // Check the unmatched table
-	 for (vector<PkgPin>::iterator I = Unmatched.begin(); 
+	 for (vector<PkgPin>::iterator I = Unmatched.begin();
 	      I != Unmatched.end() && P == 0; I++)
 	    if (I->Pkg == Name)
 	       P = &*I;
-	 
+
 	 if (P == 0)
-	    P = &*Unmatched.insert(Unmatched.end(),PkgPin());      
+	    P = &*Unmatched.insert(Unmatched.end(),PkgPin());
       }
-      else
-      {
-	 P = Pins + Pkg->ID;
-      }      
+      P->Type = Type;
+      P->Priority = Priority;
+      P->Data = Data;
    }
-   
-   // Set..
-   P->Type = Type;
-   P->Priority = Priority;
-   P->Data = Data;
 }
 									/*}}}*/
 // Policy::GetMatch - Get the matching version for a package pin	/*{{{*/