From e68ca100711326895126dc1fca86a2124a8e8d63 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 6 Jul 2009 15:46:54 +0200 Subject: Support /etc/apt/preferences.d (Closes: #535512) --- apt-pkg/policy.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'apt-pkg/policy.cc') 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 +#include +#include +#include #include #include /*}}}*/ @@ -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 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::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(); -- cgit v1.2.3