25
25
// Include Files /*{{{*/
26
26
#include <apt-pkg/policy.h>
27
#include <apt-pkg/contrib/configuration.h>
27
#include <apt-pkg/configuration.h>
28
28
#include <apt-pkg/tagfile.h>
29
#include <apt-pkg/contrib/strutl.h>
30
#include <apt-pkg/contrib/error.h>
31
#include <apt-pkg/contrib/sptr.h>
29
#include <apt-pkg/strutl.h>
30
#include <apt-pkg/fileutl.h>
31
#include <apt-pkg/error.h>
32
#include <apt-pkg/sptr.h>
33
34
#include <apti18n.h>
35
36
#include <iostream>
120
121
signed Max = GetPriority(Pkg);
121
122
pkgCache::VerIterator Pref = GetMatch(Pkg);
124
// no package = no candidate version
125
if (Pkg.end() == true)
128
// packages with a pin lower than 0 have no newer candidate than the current version
130
return Pkg.CurrentVer();
123
132
/* Falling through to the default version.. Setting Max to zero
124
133
effectively excludes everything <= 0 which are the non-automatic
125
134
priorities.. The status file is given a prio of 100 which will exclude
251
// PreferenceSection class - Overriding the default TrimRecord method /*{{{*/
252
// ---------------------------------------------------------------------
253
/* The preference file is a user generated file so the parser should
254
therefore be a bit more friendly by allowing comments and new lines
255
all over the place rather than forcing a special format */
256
class PreferenceSection : public pkgTagSection
258
void TrimRecord(bool BeforeRecord, const char* &End)
260
for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r' || Stop[0] == '#'); Stop++)
262
Stop = (const char*) memchr(Stop,'\n',End-Stop);
266
// ReadPinDir - Load the pin files from this dir into a Policy /*{{{*/
267
// ---------------------------------------------------------------------
268
/* This will load each pin file in the given dir into a Policy. If the
269
given dir is empty the dir set in Dir::Etc::PreferencesParts is used.
270
Note also that this method will issue a warning if the dir does not
271
exists but it will return true in this case! */
272
bool ReadPinDir(pkgPolicy &Plcy,string Dir)
274
if (Dir.empty() == true)
275
Dir = _config->FindDir("Dir::Etc::PreferencesParts");
277
if (FileExists(Dir) == false)
279
_error->WarningE("FileExists",_("Unable to read %s"),Dir.c_str());
283
vector<string> const List = GetListOfFilesInDir(Dir, "pref", true, true);
286
for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
287
if (ReadPinFile(Plcy, *I) == false)
243
292
// ReadPinFile - Load the pin file into a Policy /*{{{*/
244
293
// ---------------------------------------------------------------------
245
294
/* I'd like to see the preferences file store more than just pin information
259
308
if (_error->PendingError() == true)
311
PreferenceSection Tags;
263
312
while (TF.Step(Tags) == true)
265
314
string Name = Tags.FindS("Package");
266
315
if (Name.empty() == true)
267
return _error->Error(_("Invalid record in the preferences file, no Package header"));
316
return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());