]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_link
r518: * dh_movefiles has long been a sore point in debhelper. Inherited
[debhelper.git] / dh_link
diff --git a/dh_link b/dh_link
index 41754f5c24f500d3087c9a19ca77bea4a26104e6..5c2a56939dba35387c2ce3bec1aacecafa9b7de0 100755 (executable)
--- a/dh_link
+++ b/dh_link
@@ -7,6 +7,7 @@ dh_link - create symlinks in package build directories
 =cut
 
 use strict;
+use File::Find;
 use Debian::Debhelper::Dh_Lib;
 
 =head1 SYNOPSIS
@@ -41,6 +42,9 @@ when policy says they should be absolute, and relative links with as short
 a path as possible. It will also create any subdirectories it needs to to put
 the symlinks in.
 
+dh_link also scans the package build tree for existing symlinks which do not
+conform to debian policy, and corrects them (v4 only).
+
 =head1 OPTIONS
 
 =over 4
@@ -98,6 +102,29 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                error("parameters list a link without a destination.");
        }
 
+       # v4 only
+       if (! compat(3)) {
+               # Scan for existing links and add them to @links, so they
+               # are recreated policy conformant.
+               find(
+                       sub {
+                               return unless -l;
+                               my $dir=$File::Find::dir;
+                               $dir=~s/^\Q$tmp\E//;
+                               my $target = readlink($_);
+                               if ($target=~/^\//) {
+                                       push @links, $target;
+                               }
+                               else {
+                                       push @links, "$dir/$target";
+                               }
+                               push @links, "$dir/$_";
+                               doit("rm","-f",$_);
+                               
+                       },
+                       $tmp);
+       }
+       
        while (@links) {
                my $dest=pop @links;
                my $src=pop @links;