- // Look for a package pin and evaluate it.
- signed Max = GetPriority(Pkg);
- pkgCache::VerIterator Pref = GetMatch(Pkg);
-
- /* Falling through to the default version.. Setting Max to zero
- effectively excludes everything <= 0 which are the non-automatic
- priorities.. The status file is given a prio of 100 which will exclude
- not-automatic sources, except in a single shot not-installed mode.
- The second pseduo-status file is at prio 1000, above which will permit
- the user to force-downgrade things.
-
- The user pin is subject to the same priority rules as default
- selections. Thus there are two ways to create a pin - a pin that
- tracks the default when the default is taken away, and a permanent
- pin that stays at that setting.
- */
- for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; Ver++)
- {
- for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++)
- {
- /* If this is the status file, and the current version is not the
- version in the status file (ie it is not installed, or somesuch)
- then it is not a candidate for installation, ever. This weeds
- out bogus entries that may be due to config-file states, or
- other. */
- if ((VF.File()->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource &&
- Pkg.CurrentVer() != Ver)
- continue;
-
- signed Prio = PFPriority[VF.File()->ID];
- if (Prio > Max)
- {
- Pref = Ver;
- Max = Prio;
- }
- }
-
- if (Pkg.CurrentVer() == Ver && Max < 1000)
- {
- /* Elevate our current selection (or the status file itself)
- to the Pseudo-status priority. */
- if (Pref.end() == true)
- Pref = Ver;
- Max = 1000;
-
- // Fast path optimize.
- if (StatusOverride == false)
- break;
- }
+ pkgCache::VerIterator cand;
+ pkgCache::VerIterator cur = Pkg.CurrentVer();
+ int candPriority = -1;
+ pkgVersioningSystem *vs = Cache->VS;
+
+ for (pkgCache::VerIterator ver = Pkg.VersionList(); ver.end() == false; ++ver) {
+ int priority = GetPriority(ver, true);
+
+ if (priority == 0 || 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;
+ cand = ver;