[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#830159: apt-get autoremove removes kernels with "+" in the package name



Package: apt
Version: 1.2.11

When I run apt-get autoremove, apt will also remove kernels with a "+"
in the package name, e.g,

# apt-get -s autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-image-3.14.69-2+hlinux1-amd64-hlinux
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Remv linux-image-3.14.69-2+hlinux1-amd64-hlinux [3.14.69-2+hlinux1]

This is due to the "+" character not being escaped in
/etc/apt/apt.conf.d//etc/apt/apt.conf.d/01autoremove-kernels:

# head /etc/apt/apt.conf.d/01autoremove-kernels 
// DO NOT EDIT! File autogenerated by apt.auto-removal.sh
APT::NeverAutoRemove
{
   "^linux-image-3\.14\.69-2+hlinux1-amd64-hlinux$";
   "^linux-image-4\.4\.11-2-amd64-hpelinux$";
   "^linux-image-4\.4-amd64-hpelinux$";
   "^linux-headers-3\.14\.69-2+hlinux1-amd64-hlinux$";
   "^linux-headers-4\.4\.11-2-amd64-hpelinux$";
   "^linux-headers-4\.4-amd64-hpelinux$";
   "^linux-image-extra-3\.14\.69-2+hlinux1-amd64-hlinux$"; 

The "+" character is being treated as a regexp meta-character instead
of as a literal.  These kernels are obviously from a variant Debian
distribution, but others may run into the same issue.

The 01autoremove-kernels is generated by
/etc/kernel/postinst.d/apt-auto-removal (source file
debian/apt.conf.autoremove). The following code from that file
generates the blacklist:

kernels="$( (echo "$1
$unamer"; for deb in $debkernels; do echo "$list" | awk "\$2 == \"$deb\" { print \$1; }"; done; ) \
   | sed -e 's#\.#\\.#g' -e '/^$/ d' | sort -u)"

The sed line is escaping "." characters, but not "+" characters (legal
in package names).

I have attached a patch that has a fix for this problem.

-- 
Andrew Patterson
Hewlett-Packard Enterprise
commit 4c851c0d9b8d04e6c6aa44d1d380e139f0c2f7af
Author: Andrew Patterson <andrew.patterson@hpe.com>
Date:   Wed Jul 6 13:40:16 2016 -0600

    Add kernels with "+" in the package name to APT::NeverAutoRemove
    
    Escape "+" in kernel package names when generating APT::NeverAutoRemove
    list so it is not treated as a regular expression meta-character.

diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh
index e7e2ca0..608d950 100644
--- a/debian/apt.auto-removal.sh
+++ b/debian/apt.auto-removal.sh
@@ -38,7 +38,7 @@ $running_version
 $previous_version" | sort -u | sed -e '/^$/ d')"
 kernels="$( (echo "$1
 $unamer"; for deb in $debkernels; do echo "$list" | awk "\$2 == \"$deb\" { print \$1; }"; done; ) \
-   | sed -e 's#\.#\\.#g' -e '/^$/ d' | sort -u)"
+   | sed -e 's#\([\.\+]\)#\\\1#g' -e '/^$/ d' | sort -u)"
 
 generateconfig() {
 	cat <<EOF

Reply to: