[Debconf-devel] Bug#616059: Bug#616059: /usr/sbin/dpkg-reconfigure: should use dpkg-query --control-path to find path for templates/config files

Colin Watson cjwatson at debian.org
Wed Mar 2 11:59:16 UTC 2011


On Wed, Mar 02, 2011 at 09:39:49AM +0100, Raphaël Hertzog wrote:
> dpkg's internal database will evolve with multiarch and you should not
> have to hardcode this knowledge in your program. Instead of accessing
> /var/lib/dpkg/info/foo.{templates,config} you should use
> dpkg-query --control-path to find out the path to those files.

Joey, does this patch look OK to you?

I don't know if it's worth falling back to older methods if dpkg-query
--control-path is unavailable.  I normally try to be pretty conservative
about what debconf uses, but (a) dpkg 1.15.4 was in squeeze and (b) this
is only in dpkg-reconfigure, not in anything that would be run during
upgrades.

diff --git a/debian/control b/debian/control
index bced7df..e6abc84 100644
--- a/debian/control
+++ b/debian/control
@@ -16,7 +16,7 @@ Pre-Depends: perl-base (>= 5.6.1-4)
 Conflicts: cdebconf (<< 0.96), debconf-tiny, apt (<< 0.3.12.1), menu (<= 2.1.3-1), dialog (<< 0.9b-20020814-1), whiptail (<< 0.51.4-11), whiptail-utf8 (<= 0.50.17-13), debconf-utils (<< 1.3.22)
 Provides: debconf-2.0
 Replaces: debconf-tiny
-Depends: ${misc:Depends}
+Depends: ${misc:Depends}, dpkg (>= 1.15.4)
 Recommends: apt-utils (>= 0.5.1), debconf-i18n
 Suggests: debconf-doc, debconf-utils, whiptail | dialog | gnome-utils, libterm-readline-gnu-perl, libgnome2-perl, libnet-ldap-perl, perl, libqtgui4-perl, libqtcore4-perl
 XB-Python-Version: ${python:Versions}
diff --git a/dpkg-reconfigure b/dpkg-reconfigure
index 79dea84..02860e1 100755
--- a/dpkg-reconfigure
+++ b/dpkg-reconfigure
@@ -81,8 +81,6 @@ L<debconf(7)>
 
 =cut
 
-my $infodir="/var/lib/dpkg/info";
-
 use strict;
 use Debconf::Db;
 use Debconf::Gettext;
@@ -91,6 +89,17 @@ use Debconf::Config;
 use Debconf::AutoSelect qw(:all);
 use Debconf::Log qw(:all);
 
+sub control_path {
+	my $pkg=shift;
+	my $filetype=shift;
+	open (QUERY, '-|', 'dpkg-query', '--control-path', $pkg, $filetype)
+		|| die "dpkg-query: $!";
+	my $path = <QUERY>;
+	chomp $path if defined $path;
+	close QUERY;
+	return $path;
+}
+
 # Use low priority unless an option below overrides.
 Debconf::Config->priority('low');
 
@@ -179,8 +188,9 @@ foreach my $pkg (@packages) {
 	
 	if ($reload) {
 		# Load up templates just in case they aren't already.
-		Debconf::Template->load("$infodir/$pkg.templates", $pkg)
-			if -e "$infodir/$pkg.templates";
+		my $templates_path=control_path($pkg, 'templates');
+		Debconf::Template->load($templates_path, $pkg)
+			if defined $templates_path;
 	}
 
 	# Simulation of reinstalling a package, without bothering with
@@ -192,13 +202,14 @@ foreach my $pkg (@packages) {
 		          ['config',   'reconfigure', $version],
 			  ['postinst', 'configure',   $version]) {
 		my $script=shift @$info;
-		next unless -x "$infodir/$pkg.$script";
+		my $script_path=control_path($pkg, $script);
+		next unless defined $script_path and -x $script_path;
 
 		my $is_confmodule='';
 
 		if ($script ne 'config') {
 			# Test to see if the script uses debconf.
-			open (IN, "<$infodir/$pkg.$script");
+			open (IN, "<$script_path");
 			while (<IN>) {
 				if (/confmodule/i) {
 					$is_confmodule=1;
@@ -211,7 +222,7 @@ foreach my $pkg (@packages) {
 		if ($script eq 'config' || $is_confmodule) {
 			# Start up the confmodule.
 			my $confmodule=make_confmodule(
-				"$infodir/$pkg.$script", @$info);
+				$script_path, @$info);
 	
 			# Make sure any questions the confmodule registers
 			# are owned by this package.
@@ -230,7 +241,7 @@ foreach my $pkg (@packages) {
 			Debconf::Db->save;
 			
 			delete $ENV{DEBIAN_HAS_FRONTEND};
-			my $ret=system("$infodir/$pkg.$script", @$info);
+			my $ret=system($script_path, @$info);
 			if (int($ret / 256) != 0) {
 				exit int($ret / 256);
 			}

-- 
Colin Watson                                       [cjwatson at debian.org]





More information about the Debconf-devel mailing list