remove the "typename" from the const_iterators as gcc-4.4 doesn't like
[ntk/apt.git] / apt-pkg / policy.cc
index 0b8c1a8..922efb0 100644 (file)
@@ -106,7 +106,7 @@ bool pkgPolicy::InitDefaults()
 
    if (_config->FindB("Debug::pkgPolicy",false) == true)
       for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); F++)
-        cout << "Prio of " << F.FileName() << ' ' << PFPriority[F->ID] << endl; 
+        std::clog << "Prio of " << F.FileName() << ' ' << PFPriority[F->ID] << std::endl; 
    
    return true;   
 }
@@ -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;
 }
                                                                        /*}}}*/
@@ -277,9 +291,9 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir)
    if (Dir.empty() == true)
       Dir = _config->FindDir("Dir::Etc::PreferencesParts");
 
-   if (FileExists(Dir) == false)
+   if (DirectoryExists(Dir) == false)
    {
-      _error->WarningE("FileExists",_("Unable to read %s"),Dir.c_str());
+      _error->WarningE("DirectoryExists",_("Unable to read %s"),Dir.c_str());
       return true;
    }