Subject: "make install-info" with DESTDIR writes unwanted usr/share/info/dir.gz

From: Jonathan Nieder <[email-masked]>
Date: Mon, 17 Oct 2011 01:39:22 -0500

Hi,

Santiago Vila writes[1]:

> There is some code in /usr/share/automake-1.11/am/texinfos.am which
> checks whether install-info is "Debian install-info" or not:
[..]
> Now, install-info is GNU install-info, and the "if" will be always true,
> as the very first line of "install-info --version" says:
>
> This is not dpkg install-info anymore, but GNU install-info
>
> which does not contain the string "debian". As a result, packages may
> easily ship /usr/share/info/dir.gz files inside the .deb binary package,
> exactly as it happened in 2003.

"Now" means dpkg 1.15.4 (2009-09-06) and later.  dpkg does not want to
be in the business of providing its own "install-info" command.

Anyway, as far as I can tell, the check in texinfos.am for Debian
didn't make much sense in the first place.  It affected not only
people building Debian packages but anything else a person happened to
do on a Debian machine.  And as described at [2], packaging systems
which could not rely on such a check ended up removing the dir.gz file
on their own.  A more appropriate replacement for the "if Debian"
condition might be "am I installing to a staging area, or directly to
the target system?".

In other words, how about this patch?  Untested for now.
---
[1] http://bugs.debian.org/543992
[2] http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=25;bug=543992

 ChangeLog          |   13 +++++++++++++
 lib/am/texinfos.am |   15 +++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4a470bd..40d0d5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-10-17  Jonathan Nieder  <[email-masked]>
+
+	For Debian Bug#543992:
+	* lib/am/texinfos.am (install-info-am): When deciding whether to
+	add to an info/dir file, instead of checking for Debian
+	install-info, check if DESTDIR is nonempty.  Debian install-info
+	--version does not print "debian" nowadays, so the existing test
+	was never triggering.  Without this change, when preparing a
+	tarball or package in order to install it later, packagers would
+	have to remove install-info first or remove the dir file
+	afterward to avoid clobbering /usr/share/info/dir on the target
+	system.
+
 2011-10-07  Stefano Lattarini  <[email-masked]>
 
 	parallel-tests: warn on conditional TEST_EXTENSIONS definition
diff --git a/lib/am/texinfos.am b/lib/am/texinfos.am
index bfde665..3134943 100644
--- a/lib/am/texinfos.am
+++ b/lib/am/texinfos.am
@@ -208,18 +208,9 @@ install-info-am: $(INFO_DEPS)
 	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(infodir)'"; \
 	  $(INSTALL_DATA) $$files "$(DESTDIR)$(infodir)" || exit $$?; done
 	@$(POST_INSTALL)
-## Only run this code if install-info actually exists, and it is not
-## the Debian install-info.  FIXME: once Debian install-info goes
-## away, we can remove this hack.  Some versions of Debian install-info
-## print their version on stderr (e.g. 1.8.3), other do it in
-## on stdout (e.g. 1.10.15).
-##
-## Do not use
-##    install-info --version 2>&1 | sed 1q | grep -v -i debian
-## as if install-info does not exist, grep -v will be happy, and
-## therefore the code will be triggered although install-info is missing.
-	@if (install-info --version && \
-	     install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \
+## We only want to run this code if installing directly to the target system.
+## As an approximation, check if DESTDIR is empty.
+	@if test "x$(DESTDIR)" = x; then
 	  list='$(INFO_DEPS)'; test -n "$(infodir)" || list=; \
 	  for file in $$list; do \
 ## Strip directory
-- 
1.7.7