Hi Simon,

Simon Chopin wrote:

> I was also confronted to the problem. I slightly modified the postinst
> script to skip the whole thing if the version provided as argument is an
> empty string.

Good catch.  That doesn't take care of the case where the sysadmin or
a previous partial run of postinst has already replaced
.../doc/contrib/hooks with a symlink, though.

So the immediate problem was that the postinst was using "test -d" to
check for "is a directory rather than a symlink to one", which doesn't
match the behavior of the test utility which uses stat(2), not
lstat(2).  That this code is run when configuring git for the first
time just makes it easier to trigger.

How about this?  The patch you sent would go on top.

-- >8 --
Subject: debian/git.postinst: use "! test -L && test -d" to check for 
contrib/hooks symlink

As noticed in debian-1.7.4.1-4~7 (debian/git-el: avoid spurious
doc/git/contrib/emacs.old directory, 2011-03-09), "test -d" does not
distinguish between directories and symlinks to directories, while
"rmdir" does.  So the test to check if .../doc/contrib/hooks has
already been replaced by a symlink yields never succeeds, and
git.postinst tries to remove the directory to make room for a new
symlink and fails:

 Setting up git (1:1.7.7-1) ...
 rmdir: cannot remove `/usr/share/doc/git/contrib/hooks': Not a directory

This normally should not happen much in practice --- it would not be
very common for the old contrib hooks path to already be a symlink if
I am upgrading from a version where it was a directory.  But due to a
mistake in the guarding "dpkg --compare-versions" call, this code is
run when installing git for the first time, too.

The fix is simple: the intent of this test was always "is just a
directory and not a symlink to one", so let's just say so explicitly.

(The "dpkg --compare-versions" call will be corrected in a separate
patch.)

Reported-by: Євгеній Мещеряков <[email protected]>
Fixes: http://bugs.debian.org/645005
Signed-off-by: Jonathan Nieder <[email protected]>
---
 debian/changelog    |    8 ++++++++
 debian/git.postinst |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 644ffc85..14152309 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+git (1:1.7.7-1.1) unstable; urgency=low
+
+  * git.postinst: check if /usr/share/doc/git/contrib/hooks is a
+    symlink before changing it to one (thx Євгеній Мещеряков; closes:
+    #645005).
+
+ -- Jonathan Nieder <[email protected]>  Wed, 12 Oct 2011 01:03:36 -0500
+
 git (1:1.7.7-1) unstable; urgency=low
 
   * new upstream release.
diff --git a/debian/git.postinst b/debian/git.postinst
index 8cf7ad3a..4815da6e 100644
--- a/debian/git.postinst
+++ b/debian/git.postinst
@@ -35,6 +35,7 @@ fi
 # 1.7.7-1 replaces /usr/share/doc/git/contrib/hooks with a symlink,
 # but dpkg doesn't do so on package upgrade
 if dpkg --compare-versions "$2" lt '1:1.7.7-1' &&
+   ! test -L /usr/share/doc/git/contrib/hooks &&
    test -d /usr/share/doc/git/contrib/hooks; then
   rmdir /usr/share/doc/git/contrib/hooks &&
   ln -s ../../../git-core/contrib/hooks \
-- 
1.7.7




--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to