summaryrefslogtreecommitdiff
path: root/apt-pkg/policy.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/policy.cc')
-rw-r--r--apt-pkg/policy.cc83
1 files changed, 29 insertions, 54 deletions
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 3cfc32829..6da6ed606 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -4,22 +4,12 @@
/* ######################################################################
Package Version Policy implementation
-
+
This is just a really simple wrapper around pkgVersionMatch with
some added goodies to manage the list of things..
-
- Priority Table:
-
- 1000 -> inf = Downgradeable priorities
- 1000 = The 'no downgrade' pseduo-status file
- 100 -> 1000 = Standard priorities
- 990 = Config file override package files
- 989 = Start for preference auto-priorities
- 500 = Default package files
- 100 = The status file and ButAutomaticUpgrades sources
- 0 -> 100 = NotAutomatic sources like experimental
- -inf -> 0 = Never selected
-
+
+ See man apt_preferences for what value means what.
+
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
@@ -56,7 +46,7 @@ using namespace std;
file matches the V0 policy engine. */
pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner)
{
- if (Owner == 0 || &(Owner->Head()) == 0)
+ if (Owner == 0)
return;
PFPriority = new signed short[Owner->Head().PackageFileCount];
Pins = new Pin[Owner->Head().PackageCount];
@@ -73,9 +63,9 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner)
pkgVersionMatch vm("", pkgVersionMatch::None);
for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
{
- if ((F->Archive != 0 && vm.ExpressionMatches(DefRel, F.Archive()) == true) ||
- (F->Codename != 0 && vm.ExpressionMatches(DefRel, F.Codename()) == true) ||
- (F->Version != 0 && vm.ExpressionMatches(DefRel, F.Version()) == true) ||
+ if (vm.ExpressionMatches(DefRel, F.Archive()) ||
+ vm.ExpressionMatches(DefRel, F.Codename()) ||
+ vm.ExpressionMatches(DefRel, F.Version()) ||
(DefRel.length() > 2 && DefRel[1] == '='))
found = true;
}
@@ -96,48 +86,40 @@ bool pkgPolicy::InitDefaults()
for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I != Cache->FileEnd(); ++I)
{
PFPriority[I->ID] = 500;
- if ((I->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
+ if (I.Flagged(pkgCache::Flag::NotSource))
PFPriority[I->ID] = 100;
- else if ((I->Flags & pkgCache::Flag::ButAutomaticUpgrades) == pkgCache::Flag::ButAutomaticUpgrades)
+ else if (I.Flagged(pkgCache::Flag::ButAutomaticUpgrades))
PFPriority[I->ID] = 100;
- else if ((I->Flags & pkgCache::Flag::NotAutomatic) == pkgCache::Flag::NotAutomatic)
+ else if (I.Flagged(pkgCache::Flag::NotAutomatic))
PFPriority[I->ID] = 1;
}
// Apply the defaults..
SPtrArray<bool> Fixed = new bool[Cache->HeaderP->PackageFileCount];
memset(Fixed,0,sizeof(*Fixed)*Cache->HeaderP->PackageFileCount);
- signed Cur = 989;
StatusOverride = false;
- for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end();
- ++I, --Cur)
+ for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I)
{
pkgVersionMatch Match(I->Data,I->Type);
for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
{
- if (Match.FileMatch(F) == true && Fixed[F->ID] == false)
+ if (Fixed[F->ID] == false && Match.FileMatch(F) == true)
{
- if (I->Priority != 0 && I->Priority > 0)
- Cur = I->Priority;
-
- if (I->Priority < 0)
- PFPriority[F->ID] = I->Priority;
- else
- PFPriority[F->ID] = Cur;
-
- if (PFPriority[F->ID] > 1000)
+ PFPriority[F->ID] = I->Priority;
+
+ if (PFPriority[F->ID] >= 1000)
StatusOverride = true;
-
+
Fixed[F->ID] = true;
- }
- }
+ }
+ }
}
if (_config->FindB("Debug::pkgPolicy",false) == true)
for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
- std::clog << "Prio of " << F.FileName() << ' ' << PFPriority[F->ID] << std::endl;
-
- return true;
+ std::clog << "Prio of " << F.FileName() << ' ' << PFPriority[F->ID] << std::endl;
+
+ return true;
}
/*}}}*/
// Policy::GetCandidateVer - Get the candidate install version /*{{{*/
@@ -166,9 +148,7 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk
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
@@ -190,8 +170,7 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk
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 &&
- instVer == false)
+ if (VF.File().Flagged(pkgCache::Flag::NotSource) && instVer == false)
continue;
signed Prio = PFPriority[VF.File()->ID];
@@ -218,9 +197,9 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator const &Pk
Pref = Ver;
PrefSeen = true;
}
- /* Elevate our current selection (or the status file itself)
- to the Pseudo-status priority. */
- Max = 1000;
+ /* Elevate our current selection (or the status file itself) so that only
+ a downgrade can override it from now on */
+ Max = 999;
// Fast path optimize.
if (StatusOverride == false)
@@ -336,13 +315,7 @@ pkgCache::VerIterator pkgPolicy::GetMatch(pkgCache::PkgIterator const &Pkg)
APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg)
{
if (Pins[Pkg->ID].Type != pkgVersionMatch::None)
- {
- // In this case 0 means default priority
- if (Pins[Pkg->ID].Priority == 0)
- return 989;
return Pins[Pkg->ID].Priority;
- }
-
return 0;
}
APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File)
@@ -466,3 +439,5 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
return true;
}
/*}}}*/
+
+pkgPolicy::~pkgPolicy() {delete [] PFPriority; delete [] Pins;}