Package: dpkg Version: 1.18.3 Severity: normal Hi,
On a couple pam modules[1] we see the following pattern: if [ "$1" = remove ] && [ "${DPKG_MAINTSCRIPT_PACKAGE_REFCOUNT:-1}" = 1]; then : remove stuff fi However, this idiom is incorrect. Because REFCOUNT tracks the number of packages that are above 'not-installed', it will include packages that are removed but not purged. If the package in question has any conffiles or a postrm, then the above block may never be executed. The semantics of this variable make it impossible to answer when a dpkg-tracked (ie, not a conffile) file is removed (eg, there is no copy of a multiarch library installed). I propose that a new variable is introduced, that tracks the number of packages that are above 'config-files' (or maybe, at or above 'unpacked'). The idea is to more closely match the idea of "the number of packages that are installed". A package that is removed, but not purged, should not be considered in the refcount. At the very least, this very weird semantics need to be better explained in the manpage. It should explicitly mention removed but not purged packages, and it should clarify what is the value when `postrm purge` is invoked (this should also apply to my propsed variable). I note that of the 6 usages in the archive, only 2 are correct. I almost introduced 3 more incorrect ones (but luckily those packages already had postinst, so the error surfaced during testing). I used the following pattern: refcount=$(dpkg-query -f '${db:Status-Abbrev} ${binary:Package}\n' \ -W $package | grep '^i' | wc -l) if [ $refcount -eq 0 ] ; then : no binaries left, remove stuff fi [1] https://codesearch.debian.net/perpackage-results/DPKG_MAINTSCRIPT_PACKAGE_REFCOUNT/2/page_0 -- System Information: Debian Release: stretch/sid APT prefers unstable APT policy: (500, 'unstable'), (1, 'experimental') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.2.0-1-amd64 (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages dpkg depends on: ii libbz2-1.0 1.0.6-8 ii libc6 2.19-22 ii liblzma5 5.1.1alpha+20120614-2.1 ii libselinux1 2.3-2+b1 ii tar 1.28-2 ii zlib1g 1:1.2.8.dfsg-2+b1 dpkg recommends no packages. Versions of packages dpkg suggests: ii apt 1.1~exp14 -- no debconf information