]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_link
r1695: * dh_gconf: gconf schemas moved to /usr/share/gconf/schemas. Relocate
[debhelper.git] / dh_link
diff --git a/dh_link b/dh_link
index 7c51d06ca0fd8b7e2f95811c51634911e8e5a14c..5dd9da3d96843062dd271e3020c073659d76539c 100755 (executable)
--- a/dh_link
+++ b/dh_link
@@ -76,6 +76,39 @@ the X man page foo.1x
 
 =cut
 
+# This expand_path expands all path "." and ".." components, but doesn't
+# resolve symbolic links.
+sub expand_path {
+       my $start = @_ ? shift : '.';
+       my @pathname = split(m:/+:,$start);
+
+       my $entry;
+       my @respath;
+       foreach $entry (@pathname) {
+               if ($entry eq '.' || $entry eq '') {
+                       # Do nothing
+               }
+               elsif ($entry eq '..') {
+                       if ($#respath == -1) {
+                               # Do nothing
+                       }
+                       else {
+                               pop @respath;
+                       }
+               }
+               else {
+                       push @respath, $entry;
+               }
+       }
+
+       my $result;
+       foreach $entry (@respath) {
+               $result .= '/' . $entry;
+       }
+       return $result;
+}
+
+
 init();
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
@@ -126,9 +159,8 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
        
        while (@links) {
                my $dest=pop @links;
-               my $src=pop @links;
+               my $src=expand_path(pop @links);
 
-               # Relavatize src and dest.
                $src=~s:^/::;
                $dest=~s:^/::;