]> git.saurik.com Git - apt.git/commitdiff
policy: Fix the new policy implementation to handle downgrades correctly
authorJulian Andres Klode <jak@debian.org>
Mon, 10 Aug 2015 13:00:16 +0000 (15:00 +0200)
committerJulian Andres Klode <jak@debian.org>
Mon, 10 Aug 2015 13:00:16 +0000 (15:00 +0200)
This was broken previously, as we'd choose a downgrade when it's
pin was higher than the previously selected candidate.

apt-pkg/policy.cc

index e1dc3aef5b8fd04d36f1c5f8ba19422fd8427f5c..78e34a34498107f6032c068c8de2b899fb79aed6 100644 (file)
@@ -231,23 +231,22 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVerNew(pkgCache::PkgIterator const
 {
    // TODO: Replace GetCandidateVer()
    pkgCache::VerIterator cand;
+   pkgCache::VerIterator cur = Pkg.CurrentVer();
    int candPriority = -1;
-   bool candInstalled = false;
    pkgVersioningSystem *vs = Cache->VS;
 
    for (pkgCache::VerIterator ver = Pkg.VersionList(); ver.end() == false; ver++) {
       int priority = GetPriority(ver);
-      bool installed = ver->ID == Pkg.CurrentVer()->ID;
 
-      if (priority < candPriority)
-        continue;
-      if (priority < 1000
-         && (priority == candPriority || installed < candInstalled)
-         && (cand.IsGood() && vs->CmpVersion(ver.VerStr(), cand.VerStr()) < 0))
-         continue;
+        if (priority <= candPriority)
+           continue;
+
+        // TODO: Maybe optimize to not compare versions
+        if (!cur.end() && priority < 1000
+           && (vs->CmpVersion(ver.VerStr(), cur.VerStr()) < 0))
+           continue;
 
       candPriority = priority;
-      candInstalled = installed;
       cand = ver;
    }