=== modified file 'apt-pkg/cachefile.cc'
--- apt-pkg/cachefile.cc	2008-01-07 15:47:40 +0000
+++ apt-pkg/cachefile.cc	2009-07-03 06:25:16 +0000
@@ -92,7 +92,7 @@ bool pkgCacheFile::Open(OpProgress &Prog
    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

=== modified file 'apt-pkg/init.cc'
--- apt-pkg/init.cc	2007-10-25 11:25:02 +0000
+++ apt-pkg/init.cc	2009-07-03 06:25:16 +0000
@@ -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   

=== modified file 'apt-pkg/policy.cc'
--- apt-pkg/policy.cc	2009-06-09 15:33:22 +0000
+++ apt-pkg/policy.cc	2009-07-03 06:25:16 +0000
@@ -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 pkgTagS
 	    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 
    {
       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();
       

=== modified file 'apt-pkg/policy.h'
--- apt-pkg/policy.h	2006-12-14 11:39:29 +0000
+++ apt-pkg/policy.h	2009-07-03 06:25:16 +0000
@@ -84,5 +84,6 @@ class pkgPolicy : public pkgDepCache::Po
 };
 
 bool ReadPinFile(pkgPolicy &Plcy,string File = "");
+bool ReadPinDir(pkgPolicy &Plcy,string Dir = "");
 
 #endif

=== modified file 'cmdline/apt-cache.cc'
--- cmdline/apt-cache.cc	2008-11-08 19:11:14 +0000
+++ cmdline/apt-cache.cc	2009-07-03 06:25:16 +0000
@@ -401,7 +401,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;
@@ -1515,7 +1515,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

=== modified file 'debian/apt.dirs'
--- debian/apt.dirs	2008-11-01 14:35:51 +0000
+++ debian/apt.dirs	2009-07-03 06:25:16 +0000
@@ -3,6 +3,7 @@ usr/lib/apt/methods
 usr/lib/dpkg/methods/apt
 etc/apt
 etc/apt/apt.conf.d
+etc/apt/preferences.d
 etc/apt/sources.list.d
 etc/logrotate.d
 var/cache/apt/archives/partial

=== modified file 'debian/changelog'
--- debian/changelog	2009-07-01 20:43:12 +0000
+++ debian/changelog	2009-07-03 06:28:16 +0000
@@ -41,8 +41,9 @@ apt (0.7.22) UNRELEASED; urgency=low
   * apt-pkg/contrib/configuration.cc: Fix a small memory leak in
     ReadConfigFile.
   * Introduce support for the Enhances field. (Closes: #137583) 
+  * Support /etc/apt/preferences.d (Closes: #535512)
 
- -- Christian Perrier <bubulle@debian.org>  Wed, 22 Apr 2009 10:13:54 +0200
+ -- Julian Andres Klode <jak@debian.org>  Fri, 03 Jul 2009 08:27:35 +0200
 
 apt (0.7.21) unstable; urgency=low
 

