---
 autoscripts/preinst-rmdocdir |    6 ++++++
 dh_installdocs               |   21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 autoscripts/preinst-rmdocdir

diff --git a/autoscripts/preinst-rmdocdir b/autoscripts/preinst-rmdocdir
new file mode 100644
index 0000000..0a7356f
--- /dev/null
+++ b/autoscripts/preinst-rmdocdir
@@ -0,0 +1,6 @@
+if [ "$1" = upgrade ] && dpkg --compare-versions "$2" lt-nl "#VERSION#"; then
+       DIR="/usr/share/doc/#PACKAGE#"
+       # Remove the old dir, or if that fails (because the directory is
+       # not empty, for example), move it out of the way.
+       rmdir "$DIR" || mv "$DIR" "$DIR".dpkg-backup
+fi
diff --git a/dh_installdocs b/dh_installdocs
index 104b796..8c59868 100755
--- a/dh_installdocs
+++ b/dh_installdocs
@@ -91,10 +91,26 @@ option will have no effect on packages with linked 
documentation
 directories, and F<copyright>, F<changelog>, F<README.Debian>, and F<TODO> 
files will
 not be installed.
 
+If there are previous versions of the linking packages that did not
+contain the link, you should also pass B<--upgrade-link-doc> as well to
+make upgrades work properly.
+
 (An older method to accomplish the same thing, which is still supported,
 is to make the documentation directory of a package be a dangling symlink,
 before calling B<dh_installdocs>.)
 
+=item B<--upgrade-link-doc=>I<version>
+
+In addition to creating a link for the documentation directory, also
+generate a preinst script that removes the old directory (making a
+backup if it is not empty) on upgrades. This makes sure that dpkg can
+actually create the symlink (it will silently ignore the symlink if a
+directory already exists).
+
+The version number passed is the first version package version that
+contains the symlink. The preinst script will run for upgrades from any
+versions before this one.
+
 =item I<file> ...
 
 Install these files as documentation into the first package acted on. (Or
@@ -151,6 +167,7 @@ sub ensure_docdir {
 
 init(options => {
        "link-doc=s" => \$dh{LINK_DOC},
+       "upgrade-link-doc=s" => \$dh{UPGRADE_LINK_DOC},
 });
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
@@ -175,6 +192,10 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                        # the target.
                        addsubstvar($package, "misc:Depends", $dh{LINK_DOC});
                }
+
+               if ($dh{UPGRADE_LINK_DOC}) {
+                       
autoscript($package,"preinst","preinst-rmdocdir","s!#PACKAGE#!$package!g;s!#VERSION#!$dh{UPGRADE_LINK_DOC}!g");
+               }
        }
        else {
                ensure_docdir($package);
-- 
1.7.7.3




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

Reply via email to