]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/policy.cc
add volatile sources support in libapt-pkg
[apt.git] / apt-pkg / policy.cc
index 78e34a34498107f6032c068c8de2b899fb79aed6..170da7c6383e26e193604d8c3ec81aefbabefeba 100644 (file)
@@ -45,7 +45,7 @@ using namespace std;
 // ---------------------------------------------------------------------
 /* Set the defaults for operation. The default mode with no loaded policy
    file matches the V0 policy engine. */
-pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner)
+pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner), d(NULL)
 {
    if (Owner == 0)
       return;
@@ -238,7 +238,7 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVerNew(pkgCache::PkgIterator const
    for (pkgCache::VerIterator ver = Pkg.VersionList(); ver.end() == false; ver++) {
       int priority = GetPriority(ver);
 
-        if (priority <= candPriority)
+        if (priority == 0 || priority <= candPriority)
            continue;
 
         // TODO: Maybe optimize to not compare versions
@@ -376,8 +376,17 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver)
    int priority = INT_MIN;
    for (pkgCache::VerFileIterator file = Ver.FileList(); file.end() == false; file++)
    {
-        if (GetPriority(file.File()) > priority)
-           priority = GetPriority(file.File());
+      /* 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 (file.File().Flagged(pkgCache::Flag::NotSource) && Ver.ParentPkg().CurrentVer() != Ver) {
+        if (priority < 0)
+              priority = 0;
+      } else if (GetPriority(file.File()) > priority) {
+        priority = GetPriority(file.File());
+      }
    }
 
    return priority == INT_MIN ? 0 : priority;
@@ -387,21 +396,6 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &Fi
    return PFPriority[File->ID];
 }
                                                                        /*}}}*/
-// PreferenceSection class - Overriding the default TrimRecord method  /*{{{*/
-// ---------------------------------------------------------------------
-/* The preference file is a user generated file so the parser should
-   therefore be a bit more friendly by allowing comments and new lines
-   all over the place rather than forcing a special format */
-class PreferenceSection : public pkgTagSection
-{
-   void TrimRecord(bool /*BeforeRecord*/, const char* &End)
-   {
-      for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r' || Stop[0] == '#'); Stop++)
-        if (Stop[0] == '#')
-           Stop = (const char*) memchr(Stop,'\n',End-Stop);
-   }
-};
-                                                                       /*}}}*/
 // ReadPinDir - Load the pin files from this dir into a Policy         /*{{{*/
 // ---------------------------------------------------------------------
 /* This will load each pin file in the given dir into a Policy. If the
@@ -446,8 +440,8 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
    pkgTagFile TF(&Fd);
    if (_error->PendingError() == true)
       return false;
-   
-   PreferenceSection Tags;
+
+   pkgUserTagSection Tags;
    while (TF.Step(Tags) == true)
    {
       // can happen when there are only comments in a record