Skip Menu |
 

This queue is for tickets about the File-Spec CPAN distribution.

Report information
The Basics
Id: 6972
Status: new
Priority: 0/
Queue: File-Spec

People
Owner: Nobody in particular
Requestors: jll [...] soundobjectlogic.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.87_01
Fixed in: (no value)



Subject: poor canonpath breaks abs2rel when $base starts with ../
Download (untitled) / with headers
text/plain 3.1k
Copy of my posts to clpm From: Jean-Louis Leroy <jll@soundobjectlogic.com> Subject: Computing symlinks, troubles with File::Spec::abs2rel Newsgroups: comp.lang.perl.misc Date: Thu, 15 Jul 2004 09:45:10 GMT Organization: Sound Object Logic I'm trying to write a function that would take exactly the same arguments as File::Copy::copy but it would create the appropriate symlink instead. It looks like abs2rel can compute that symlink for me but I'm having problems. Probably I misread the spec... Consider the following directory structure: /tmp/Foo /tmp/Foo/blib /tmp/Foo/blib/lib /tmp/Foo/blib/lib/Foo /tmp/Foo/blib/lib/Foo/Bar /tmp/Foo/Foo /tmp/Foo/Foo/This.pm /tmp/Foo/Bar /tmp/Foo/Bar/Bar /tmp/Foo/Bar/Bar/That.pm You'll probably recognize the kind of structure laid out by h2xs (at least perl 5.6.1 versions of it); btw my purpose with this is to ease debugging of modules by preventing ExtUtils::Install from making copies of the sources. The program below creates that structure, then chdirs to /tmp/Foo and uses abs2rel to compute a symlink from /tmp/Foo/blib/lib/Foo.pm to /tmp/Foo/Foo.pm. That much works. Now I try the same trick from /tmp/Foo/Bar, because that's where ExtUtils puts me in the real situation. Thus 'blib' is one level up: chdir '/tmp/Foo/Bar'; $link = abs2rel('Bar/That.pm', dirname '../blib/lib/Foo/Bar/That.pm'); Well that returns an invalid link. Some ideas? TIA... # perl -v = This is perl, v5.8.2 built for i686-linux # $File::Spec::VERSION = 0.87 # $File::Spec::Functions::VERSION = 1.3 # $File::Spec::Unix::VERSION = 1.5 use strict; use File::Path; use File::Spec::Functions qw( abs2rel ); use File::Basename; use Cwd; chdir '/tmp' or die; mkdir $_ for qw( Foo Foo/blib Foo/blib/lib Foo/blib/lib/Foo Foo/blib/lib/Foo/Bar Foo/Foo Foo/Bar Foo/Bar/Bar ); open FH, ">$_" or die for qw( Foo/Foo/This.pm Foo/Bar/Bar/That.pm ); print "\n"; system 'find /tmp/Foo'; sub gotodir { chdir $_[0] or die; print "cwd = $_[0]\n"; } gotodir '/tmp/Foo'; my $link = abs2rel('Foo/This.pm', dirname 'blib/lib/Foo/This.pm'); print "way = $link\n"; gotodir 'blib/lib/Foo' or die; print "...is wrong\n" unless open(FH, $link) ; print "\n"; gotodir '/tmp/Foo/Bar'; $link = abs2rel('Bar/That.pm', dirname '../blib/lib/Foo/Bar/That.pm'); print "way = $link\n"; gotodir '/tmp/Foo/blib/lib/Foo/Bar' or die; print "...is wrong\n" unless open(FH, $link) ; -- Jean-Louis Leroy Sound Object Logic http://www.soundobjectlogic.com From: Jean-Louis Leroy <jll@soundobjectlogic.com> Subject: Re: Computing symlinks, troubles with File::Spec::abs2rel Newsgroups: comp.lang.perl.misc Date: Thu, 15 Jul 2004 10:34:36 GMT Organization: Sound Object Logic I should have looked at the source one hour ago...I think that the problem is that abs2rel first runs its arguments through rel2abs. Now in my example, this results in the $base argument to be converted to: /tmp/Foo/Bar/../blib/lib/Foo/Bar. As far as Unix' is concerned this is the same as /tmp/Foo/blib/lib/Foo/Bar, but that breaks the algorithm that abs2rel uses. -- Jean-Louis Leroy Sound Object Logic http://www.soundobjectlogic.com
Download patch
application/octet-stream 864b

Message body not shown because it is not plain text.

To: bug-File-Spec [...] rt.cpan.org
Subject: Re: [cpan #6972] AutoReply: poor canonpath breaks abs2rel when $base starts with ../
From: Jean-Louis Leroy <jll [...] soundobjectlogic.com>
Date: Thu, 15 Jul 2004 16:33:06 +0200
RT-Send-Cc:
Download (untitled) / with headers
text/plain 371b
In the meantime, I found out that this: 1 while $path =~ s{ / ( \. \. [^/]+ | \. [^./] [^/]* | [^./] [^/]* ) / \.\. / }{/}x; ...works better than: $path =~ s{ / ( \. \. [^/]+ | \. [^./] [^/]* | [^./] [^/]* ) / \.\. / }{/}gx; ...because it will handle cases like: xx/yy/../../zz Cordially, Jean-Louis Leroy Sound Object Logic http://www.soundobjectlogic.com


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.