summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-06 17:09:08 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-06 17:09:08 +0200
commit13aa7588f24c4bc60c865071361d7be6e20c7086 (patch)
tree950ce0071a391a46f941d4b414bd929b1763e3f9 /apt-pkg
parent5541fea3f0c6b4b40048c161b9201b03243ac3a9 (diff)
parente68ca100711326895126dc1fca86a2124a8e8d63 (diff)
Support /etc/apt/preferences.d, by adding ReadPinDir() (Closes: #535512)
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cachefile.cc2
-rw-r--r--apt-pkg/init.cc1
-rw-r--r--apt-pkg/policy.cc50
-rw-r--r--apt-pkg/policy.h1
4 files changed, 52 insertions, 2 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index 1a84aea54..5b5e26497 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -92,7 +92,7 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
Policy = new pkgPolicy(Cache);
if (_error->PendingError() == true)
return false;
- if (ReadPinFile(*Policy) == false)
+ if (ReadPinFile(*Policy) == false || ReadPinDir(*Policy) == false)
return false;
// Create the dependency cache
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
index 338bef66c..4abfb726f 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -67,6 +67,7 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::Etc::main","apt.conf");
Cnf.Set("Dir::Etc::parts","apt.conf.d");
Cnf.Set("Dir::Etc::preferences","preferences");
+ Cnf.Set("Dir::Etc::preferencesparts","preferences.d");
Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
// State
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 98576fc91..b9a951990 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -32,6 +32,9 @@
#include <apti18n.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <algorithm>
#include <iostream>
#include <sstream>
/*}}}*/
@@ -253,6 +256,51 @@ class PreferenceSection : public pkgTagSection
Stop = (const char*) memchr(Stop,'\n',End-Stop);
}
};
+
+
+bool ReadPinDir(pkgPolicy &Plcy,string Dir)
+{
+ if (Dir.empty() == true)
+ Dir = _config->FindDir("Dir::Etc::PreferencesParts");
+
+ 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++)
+ if (isalpha(*C) == 0 && isdigit(*C) == 0 && *C != '_' && *C != '-')
+ 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);
+ }
+ closedir(D);
+
+ sort(List.begin(),List.end());
+
+ // Read the files
+ for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
+ if (ReadPinFile(Plcy, *I) == false)
+ return false;
+ return true;
+}
+
/*}}}*/
// ReadPinFile - Load the pin file into a Policy /*{{{*/
// ---------------------------------------------------------------------
@@ -278,7 +326,7 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
{
string Name = Tags.FindS("Package");
if (Name.empty() == true)
- return _error->Error(_("Invalid record in the preferences file, no Package header"));
+ return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
if (Name == "*")
Name = string();
diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h
index d5f3b2f75..4894682fa 100644
--- a/apt-pkg/policy.h
+++ b/apt-pkg/policy.h
@@ -84,5 +84,6 @@ class pkgPolicy : public pkgDepCache::Policy
};
bool ReadPinFile(pkgPolicy &Plcy,string File = "");
+bool ReadPinDir(pkgPolicy &Plcy,string Dir = "");
#endif