Hi,

2011/5/12 Guillem Jover <guil...@debian.org>:
>> You can find the test case attached which works OK with current
>> unstable dpkg and fails with git version+your patch.
>
> Ah! Now I see, and indeed it does. So the problem here is that
> removal_bulk_remove_configfiles() is buggy as it does not remove the
> conffiles from the package files list when it unlinks them, and they
> linger around when we are removing the leftover directories on purge.
> On entry removal_bulk_remove_leftover_dirs() should really only
> contain directories (or symlinks to directories) nothing else. I'll
> fix that up.

Cool :).

> You are absolutely right, sorry I didn't see it before.

No problem at all. I am glad that we found a new bug in dpkg in the
process. And we have one more test case, which always helps.

>> I see, you're right. After reading the summary and the original bug
>> reports I see only two solutions to this problem:
>>
>> a) teach dpkg to remove parent directories not used by other packages
>> on purge (slight modification of Raphael's case one)
>
>> b) write some logic to dpkg-maintscript-helper which would allow the
>> maintainers to either specify directories to purge in postrm, or
>> directories to keep in the list on remove.
>>
>> I don't think it's feasible to search the directories for files not
>> used by other packages, this would make dpkg very slow in corner cases
>> (many files in many directories).
>
> While I don't think it might cause a huge degradation, I agree though
> it's not really the correct solution.
>
>> ( c) would be the simplest solution - just keep directories used by
>> more packages in the list and remove them on purge, but that's very
>> ugly)
>
> The correct solution is to teach dpkg about external files.

But that's a long term solution I guess... What about doing b) in meantime.

a) it would be optional for maintainers to use in postinst... f.e. I could add:

dpkg-maintscript-helper purge_dir /etc/php5/conf.d to php5-common postinst
and
dpkg-maintscript-helper purge_dir /etc/php5/cli to php5-cli postinst

b) it could be integrated with ucf (ie. ucf would call the script)

That would solve most cases.

[...meanwhile...]

I have implemented the command. It doesn't go with corresponding
manpage section and probably needs some polishing, but it works in my
case...

In fact, I needed to add

dpkg-maintscript-helper purge_dir $phpini

only to php5-cli.postrm to cleanup the cruft.

O.
-- 
Ondřej Surý <ond...@sury.org>
http://blog.rfc1925.org/
From 30052530771205d052e9113e3ccb23d36349f8c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ond...@sury.org>
Date: Thu, 12 May 2011 16:40:03 +0200
Subject: [PATCH] Add purge_dir command to dpkg-maintscript-helper

---
 scripts/dpkg-maintscript-helper.sh |   38 +++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/scripts/dpkg-maintscript-helper.sh b/scripts/dpkg-maintscript-helper.sh
index 631a5a1..91cd072 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -216,6 +216,39 @@ abort_mv_conffile() {
 	fi
 }
 
+purge_dir() {
+	local DIRECTORY="$1"
+	local PACKAGE="$2"
+	if [ "${PACKAGE}" = "--" -o -z "${PACKAGE}" ]; then
+		PACKAGE="${DPKG_MAINTSCRIPT_PACKAGE}"
+	fi
+
+	while [ "$DIRECTORY" != "/" ]; do
+
+		local OWNED_BY="$(dpkg-query -S "${DIRECTORY}" 2>/dev/null | cut -f 1 -d :)"
+
+		if [ -z "${OWNED_BY}" -o "${OWNED_BY}" = "${PACKAGE}" ]; then
+			[ -d "${DIRECTORY}" ] && \
+			    rmdir --ignore-fail-on-non-empty "${DIRECTORY}"
+
+			# Directory was not removed
+			if [ -d "${DIRECTORY}" ]; then
+				echo "Unable to remove ${DIRECTORY}: directory not empty"
+				return 1
+			else
+				DIRECTORY="$(dirname "${DIRECTORY}")"
+				purge_dir "${DIRECTORY}" "${PACKAGE}"
+				return $?
+			fi
+		else
+			debug "Preserving ${DIRECTORY}; still owned by ${#OWNED_BY} package(s)"
+			return 0
+		fi
+	done
+
+	return 0
+}
+
 # Common functions
 debug() {
 	if [ -n "$DPKG_DEBUG" ]; then
@@ -272,7 +305,7 @@ shift
 case "$command" in
 supports)
 	case "$1" in
-	rm_conffile|mv_conffile)
+	rm_conffile|mv_conffile|purge_dir)
 		code=0
 		;;
 	*)
@@ -295,6 +328,9 @@ rm_conffile)
 mv_conffile)
 	mv_conffile "$@"
 	;;
+purge_dir)
+	purge_dir "$@"
+	;;
 --help|help|-?|-h)
 	usage
 	;;
-- 
1.7.2.5

Reply via email to