Package: debhelper
Version: 11.1.6
Severity: minor
Tags: patch

Hello.

The attached script shows that dh_usrlocal generates a prerm script
removing a direct subdirectory of /usr/local.
As I understand the policy, it should not.

The fix is included.
It also suggests some minor related changes, which do not seem to change the 
behaviour.
--- a/dh_usrlocal
+++ b/dh_usrlocal
@@ -82,6 +82,8 @@
 		      wanted => sub {
 			my $fn = $File::Find::name;
 			if (-d $fn) {
+				return if $fn eq  "$tmp/usr/local";
+
 				my $user = 'root';
 				my $group = 'staff';
 				my $mode = '02775';
@@ -99,12 +101,13 @@
 
 
 				$fn =~ s!^\Q$tmp\E!!;
-				return if $fn eq '/usr/local';
-				
-				# @dirs is in parents-first order for dir creation...
-				unshift @dirs, "$fn $mode $user $group";
-				# ...whereas @justdirs is depth-first for removal.
-				push @justdirs, $fn;
+
+				push @dirs, "$fn $mode $user $group";
+
+				# don't remove directories directly in /usr/local
+				if ($File::Find::dir ne "$tmp/usr/local") {
+					push @justdirs, $fn;
+				}
 				doit('rmdir', $_);
 			}
 			else {
@@ -118,11 +121,10 @@
 		# This constructs the body of a 'sed' c\ expression which
 		# is parsed by the shell in double-quotes
 		my $dirs = join("$ebs\n", sort @dirs);
-		pop @justdirs; # don't remove directories directly in /usr/local
 		my $justdirs = join("$ebs\n", reverse sort @justdirs);
 		if (! $dh{NOSCRIPTS}) { 
 			autoscript($package,"postinst", "postinst-usrlocal",
-				   "/#DIRS#/ c${ebs}\n${dirs}");
+				   "/#DIRS#/ c${ebs}\n${dirs}") if length $dirs;
 			autoscript($package,"prerm", "prerm-usrlocal",
 				   "/#JUSTDIRS#/ c${ebs}\n${justdirs}") if length $justdirs;
 		}

Attachment: dh_usrlocal-topdirs.sh
Description: Bourne shell script

Reply via email to