add new packaging feature debian/<package>.purge

Goal description

"debian/postrm" scripts currently contain a lot of calls to 'rm' or 'rmdir'; running these two commands will give you a quick overview:

grep "rmdir --ignore-fail-on-non-empty" /var/lib/dpkg/info/*.postrm
grep "rm -f" /var/lib/dpkg/info/*.postrm

Here is a (very small) sample (grep "rm -f" /var/lib/dpkg/info/*.postrm | grep -v \* | wc -l gives me 187):

/var/lib/dpkg/info/adduser.postrm:    rm -f /etc/adduser.conf
/var/lib/dpkg/info/console-setup.postrm:    rm -f /etc/default/console-setup
/var/lib/dpkg/info/debian-archive-keyring.postrm:  rm -f /etc/apt/trusted.gpg.d/debian-archive-keyring.gpg
/var/lib/dpkg/info/grub-pc.postrm:    rm -f /etc/default/grub
/var/lib/dpkg/info/locales.postrm:      rm -f /etc/locale.gen
/var/lib/dpkg/info/locales.postrm:      rm -f /etc/default/locale
/var/lib/dpkg/info/lsb-release.postrm:                rm -f /etc/lsb-release
/var/lib/dpkg/info/readline-common.postrm:      rm -f /etc/inputrc
/var/lib/dpkg/info/util-linux.postrm:           rm -f /etc/adjtime

this could be moved to "debian/<package>.purge" files only containing the path:

# comment
# the files are processed in the order specified in this file
# so: first files & the eventually volatile folders
# holding those files
/path/to/folder/file
# this is the same as calling "rmdir --ignore-fail-on-non-empty"
# folders must end with a '/' to be recognized as such
/path/to/folder/

If postrm exists, theses files would be proceeded after it and only it exited successfully.

Advantages

1. dpkg --search could help users known where some loose file in /etc comes from; it would work like locate -e and only match existing files.

2. dpkg --listfiles could show those, but we must check if it is backward compatible

if [ "$1" = purge ]; then
        rm -rf /somefile
fi

it would completely go away. dpkg would avoid starting a shell, making the removal faster. A simple unlink() is much more lightweight.

Current status

Draft

Questions

Some packages will need runtime registration of files to purge on package removal, how can we accommodate those?