~ubuntu-branches/debian/experimental/apt/experimental

« back to all changes in this revision

Viewing changes to apt-pkg/policy.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-02-18 22:07:23 UTC
  • mfrom: (9.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100218220723-zb7zdh6fmsmp30tr
Tags: 0.7.26~exp2
fix crash when LANGUAGE is not set

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
                                                                        /*}}}*/
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>
32
 
    
 
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
 
33
34
#include <apti18n.h>
34
35
 
35
36
#include <iostream>
120
121
   signed Max = GetPriority(Pkg);
121
122
   pkgCache::VerIterator Pref = GetMatch(Pkg);
122
123
 
 
124
   // no package = no candidate version
 
125
   if (Pkg.end() == true)
 
126
      return Pref;
 
127
 
 
128
   // packages with a pin lower than 0 have no newer candidate than the current version
 
129
   if (Max < 0)
 
130
      return Pkg.CurrentVer();
 
131
 
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
239
248
   return 0;
240
249
}
241
250
                                                                        /*}}}*/
242
 
 
 
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
 
257
{
 
258
   void TrimRecord(bool BeforeRecord, const char* &End)
 
259
   {
 
260
      for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r' || Stop[0] == '#'); Stop++)
 
261
         if (Stop[0] == '#')
 
262
            Stop = (const char*) memchr(Stop,'\n',End-Stop);
 
263
   }
 
264
};
 
265
                                                                        /*}}}*/
 
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)
 
273
{
 
274
   if (Dir.empty() == true)
 
275
      Dir = _config->FindDir("Dir::Etc::PreferencesParts");
 
276
 
 
277
   if (FileExists(Dir) == false)
 
278
   {
 
279
      _error->WarningE("FileExists",_("Unable to read %s"),Dir.c_str());
 
280
      return true;
 
281
   }
 
282
 
 
283
   vector<string> const List = GetListOfFilesInDir(Dir, "pref", true, true);
 
284
 
 
285
   // Read the files
 
286
   for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
 
287
      if (ReadPinFile(Plcy, *I) == false)
 
288
         return false;
 
289
   return true;
 
290
}
 
291
                                                                        /*}}}*/
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)
260
309
      return false;
261
310
   
262
 
   pkgTagSection Tags;
 
311
   PreferenceSection Tags;
263
312
   while (TF.Step(Tags) == true)
264
313
   {
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());
268
317
      if (Name == "*")
269
318
         Name = string();
270
319