How can I apt-pin stable?

I changed my mind some time after install, and would prefer stable to testing for this particular system. Unfortunately, I currently have packages at old testing versions. I need to force a downgrade to get them back on the squeeze track while keeping one or two (plus dependencies) at testing versions. Sadly my preferences file isn't playing well with others. I've tried many variations on version n=, version a=, etc.

bash# cat /etc/apt/preferences.d/pinstable
Package: *
Pin: release a=testing
Pin-Priority: -10

Package: *
Pin: release a=stable
Pin-Priority: 1010

I have the default release set to stable:

bash# cat /etc/apt/preferences.d/apt.conf.d/99release
APT::Default-Release "stable";

Here's an example using a random package that has a few possible versions:

bash# apt-cache policy libapache2-mod-php5
libapache2-mod-php5:
  Installed: 5.3.6-13
  Candidate: 5.3.6-13
  Version table:
     5.3.9-1 0
        -10 http://mirror.rit.edu/debian/ testing/main i386 Packages
 *** 5.3.6-13 0
        100 /var/lib/dpkg/status
     5.3.3-7+squeeze7 0
        990 http://security.debian.org/ squeeze/updates/main i386 Packages
     5.3.3-7+squeeze3 0
        990 http://mirror.rit.edu/debian/ squeeze/main i386 Packages

Why aren't the squeeze versions at priority 1010?


Solution 1:

The problem here is your /etc/apt/apt.conf.d/99release file.

From man 5 apt_preferences

   If the target release has been specified then APT uses the following
   algorithm to set the priorities of the versions of a package. Assign:

   priority 990
       to the versions that are not installed and belong to the target
       release.

It appears that having an explicit release mentioned in APT will override any pin settings. I setup a test system and with a similar 99release file, and pinstable file I see the exact same values as you from apt-cache. But if I remeve the 99release file I get this.

# apt-cache policy libapache2-mod-php5
libapache2-mod-php5:
  Installed: (none)
  Candidate: 5.3.3-7+squeeze8
  Version table:
     5.3.3-7+squeeze8 0
       1010 http://security.debian.org/ squeeze/updates/main amd64 Packages
     5.3.3-7+squeeze3 0
       1010 http://ftp.us.debian.org/debian/ squeeze/main amd64 Packages