summaryrefslogtreecommitdiff
path: root/apt-pkg/policy.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-07-21 18:31:36 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2009-07-21 18:31:36 +0200
commitd59725349555939d39af81cf7746069d6aa3536c (patch)
tree90a85a3e4ffef76d9572ecf4a1dc8323f7ea38c9 /apt-pkg/policy.cc
parent02e8ba352f71b82a936f5034059251425ab183d5 (diff)
parentc5f44afc2446d738e30ea4c6021d4b60915546b1 (diff)
The 'not dead yet' release
* add hook for MarkInstall and MarkDelete (closes: #470035) * add the various foldmarkers in apt-pkg & cmdline (no code change) * versions with a pin of -1 shouldn't be a candidate (Closes: #355237) * prefer mmap as memory allocator in MMap instead of a static char array which can (at least in theory) grow dynamic * eliminate (hopefully all) segfaults in pkgcachegen.cc and mmap.cc which can arise if cache doesn't fit into the mmap (Closes: #535218) * display warnings instead of errors if the parts dirs doesn't exist * honor the dpkg hold state in new Marker hooks (closes: #64141)
Diffstat (limited to 'apt-pkg/policy.cc')
-rw-r--r--apt-pkg/policy.cc38
1 files changed, 28 insertions, 10 deletions
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index b9a951990..81fdb0431 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -123,6 +123,14 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg)
signed Max = GetPriority(Pkg);
pkgCache::VerIterator Pref = GetMatch(Pkg);
+ // no package = no candidate version
+ if (Pkg.end() == true)
+ return Pref;
+
+ // packages with a pin lower than 0 have no newer candidate than the current version
+ if (Max < 0)
+ return Pkg.CurrentVer();
+
/* 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
@@ -256,24 +264,35 @@ class PreferenceSection : public pkgTagSection
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
+ given dir is empty the dir set in Dir::Etc::PreferencesParts is used.
+ Note also that this method will issue a warning if the dir does not
+ exists but it will return true in this case! */
bool ReadPinDir(pkgPolicy &Plcy,string Dir)
{
if (Dir.empty() == true)
Dir = _config->FindDir("Dir::Etc::PreferencesParts");
+ if (FileExists(Dir) == false)
+ {
+ _error->WarningE("FileExists",_("Unable to read %s"),Dir.c_str());
+ return true;
+ }
+
DIR *D = opendir(Dir.c_str());
if (D == 0)
return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
vector<string> List;
-
+
for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
{
if (Ent->d_name[0] == '.')
continue;
-
+
// Skip bad file names ala run-parts
const char *C = Ent->d_name;
for (; *C != 0; C++)
@@ -281,17 +300,17 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir)
break;
if (*C != 0)
continue;
-
+
// Make sure it is a file and not something else
string File = flCombine(Dir,Ent->d_name);
struct stat St;
if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
continue;
-
- List.push_back(File);
- }
+
+ List.push_back(File);
+ }
closedir(D);
-
+
sort(List.begin(),List.end());
// Read the files
@@ -300,7 +319,6 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir)
return false;
return true;
}
-
/*}}}*/
// ReadPinFile - Load the pin file into a Policy /*{{{*/
// ---------------------------------------------------------------------