At Mon, 15 Mar 2004 00:53:25 +0900,
GOTO Masanori wrote:
> At Sun, 14 Mar 2004 12:31:37 +0900,
> GOTO Masanori wrote:
> > Joey, please look at this patch.  How to test in libc6-dev as following:
> > 
> >     > ln -sf ../../lib/libm.so debian/libc6-dev/usr/lib/libm.so ; ls -l 
> > debian/libc6-dev/usr/lib/libm.so
> >     lrwxrwxrwx    1 gotom    gotom          17 2004-03-14 12:26 
> > debian/libc6-dev/usr/lib/libm.so -> ../../lib/libm.so
> >     > dh_link.new -plibc6-dev ; ls -l debian/libc6-dev/usr/lib/libm.so
> >     lrwxrwxrwx    1 gotom    gotom          18 2004-03-14 12:26 
> > debian/libc6-dev/usr/lib/libm.so -> /lib/libm-2.3.2.so
> 
> Umm, this patch has the bug.  The resolved symlink path should be
> "/lib/libm.so"...

The problem is that if /lib/libm.so is existed, then this path keeps
resolving to /lib/libm-2.3.2.so because readlink(2) resolves both
. and .. and symlinks.  So we can't use abs_path() for this purpose.

I implement path expand routine which resolve . and .., but don't
resolve symbolic links. 

This patch can handle to expand pathname even if the first character
in $src component includes `..' or `.'.


--- dh_link     2004-03-12 18:49:27.000000000 +0900
+++ dh_link.new 2004-03-15 02:09:35.000000000 +0900
@@ -78,6 +78,39 @@
 
 init();
 
+# expand_path expands all path "." and ".." component, but don'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;
+               }
+       }
+
+       # reconstruct full pathname
+       my $result;
+       foreach $entry (@respath) {
+               $result .= '/' . $entry;
+       }
+
+       return $result;
+}
+               
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
        my $tmp=tmpdir($package);
        my $file=pkgfile($package,"links");
@@ -128,6 +161,9 @@
                my $dest=pop @links;
                my $src=pop @links;
 
+               # Expand . and .. in src.
+               $src=expand_path($src);
+       
                # Relavatize src and dest.
                $src=~s:^/::;
                $dest=~s:^/::;


        > ln -sf ../../lib/libm.so debian/libc6-dev/usr/lib/libm.so ; ls -l 
debian/libc6-dev/usr/lib/libm.so
        lrwxrwxrwx    1 gotom    gotom          17 2004-03-15 02:11 
debian/libc6-dev/usr/lib/libm.so -> ../../lib/libm.so
        > ./dh_link -plibc6-dev ; ls -l debian/libc6-dev/usr/lib/libm.so
        lrwxrwxrwx    1 gotom    gotom          12 2004-03-15 02:11 
debian/libc6-dev/usr/lib/libm.so -> /lib/libm.so

I keep testing for another path examples.

Regards,
-- gotom


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

Reply via email to