From dceb12217d3652425f1e7c4c4d77d430c394c71d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 6 Jul 2009 15:46:54 +0200 Subject: [PATCH] Support /etc/apt/preferences.d (Closes: #535512) (cherry picked from commit e68ca100711326895126dc1fca86a2124a8e8d63) Conflicts: apt/apt-pkg/init.cc apt/apt-pkg/policy.cc debian/apt.dirs debian/changelog --- apt/apt-pkg/cachefile.cc | 2 +- apt/apt-pkg/init.cc | 1 + apt/apt-pkg/policy.cc | 49 +++++++++++++++++++++++++++++++++++++++- apt/apt-pkg/policy.h | 1 + apt/cmdline/apt-cache.cc | 4 ++-- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/apt/apt-pkg/cachefile.cc b/apt/apt-pkg/cachefile.cc index c3b9e5a..48ab404 100644 --- a/apt/apt-pkg/cachefile.cc +++ b/apt/apt-pkg/cachefile.cc @@ -100,7 +100,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/apt-pkg/init.cc b/apt/apt-pkg/init.cc index eeaed84..c97879b 100644 --- a/apt/apt-pkg/init.cc +++ b/apt/apt-pkg/init.cc @@ -86,6 +86,7 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.CndSet("Dir::Etc::main","apt.conf"); Cnf.CndSet("Dir::Etc::parts","apt.conf.d"); Cnf.CndSet("Dir::Etc::preferences","preferences"); + Cnf.CndSet("Dir::Etc::preferencesparts","preferences.d"); Cnf.CndSet("Dir::Bin::methods",LIBDIR "/apt/methods"); Cnf.CndSet("Acquire::ComprExtension", ".bz2"); diff --git a/apt/apt-pkg/policy.cc b/apt/apt-pkg/policy.cc index b4654f7..f30b223 100644 --- a/apt/apt-pkg/policy.cc +++ b/apt/apt-pkg/policy.cc @@ -37,6 +37,9 @@ #include +#include +#include +#include #include /*}}}*/ @@ -299,6 +302,50 @@ signed short pkgPolicy::GetPkgPriority(const pkgCache::PkgIterator &Pkg) } return Max; } + +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 /*{{{*/ @@ -325,7 +372,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/apt-pkg/policy.h b/apt/apt-pkg/policy.h index 563c8d7..f4ec09c 100644 --- a/apt/apt-pkg/policy.h +++ b/apt/apt-pkg/policy.h @@ -94,5 +94,6 @@ class pkgPolicy : public pkgDepCache::Policy }; bool ReadPinFile(pkgPolicy &Plcy,string File = ""); +bool ReadPinDir(pkgPolicy &Plcy,string Dir = ""); #endif diff --git a/apt/cmdline/apt-cache.cc b/apt/cmdline/apt-cache.cc index 85a4280..cdb5edc 100644 --- a/apt/cmdline/apt-cache.cc +++ b/apt/cmdline/apt-cache.cc @@ -400,7 +400,7 @@ bool DumpAvail(CommandLine &Cmd) pkgCache &Cache = *GCache; pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false) + if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) return false; unsigned long Count = Cache.HeaderP->PackageCount+1; @@ -1742,7 +1742,7 @@ bool Policy(CommandLine &CmdL) pkgCache &Cache = *GCache; pkgPolicy Plcy(&Cache); - if (ReadPinFile(Plcy) == false) + if (ReadPinFile(Plcy) == false || ReadPinDir(Plcy) == false) return false; // Print out all of the package files