On 2005–12–10, at 07:28, Tetsuro KURITA wrote:

I find a problem of a rel2abs method of File::Spec module.
rel2abs can't treat relative paths which starts with '../'.

example:

use File::Spec;

my $relpath = "../hello";
my $basepath = "/aaa/bbb/ccc";

my $abspath = File::Spec->rel2abs($relpath,$basepath);
print "$abspath\n"; ## result: /aaa/bbb/ccc/../hello


I guess the result should be '/aaa/bbb/hello'
As a result of checking source of File::Spec, It seems that File::Spec::Unix module don't consider relative path starts with '../'.

I could not find an address of a place to which I should report. Could you anyone tell me how I should deal with this problem.

I don't think it's a bug. rel2abs uses canonpath to clean up the path it creates. But the File::Spec documentation for canonpath says

       canonpath
No physical check on the filesystem, but a logical cleanup of a path.

             $cpath = File::Spec->canonpath( $path ) ;

Note that this does *not* collapse x/../y sections into y. This is by design. If /foo on your system is a symlink to /bar/ baz, then /foo/../quux is actually /bar/quux, not /quux as a naive ../-removal would give you. If you want to do this kind of processing, you prob- ably want "Cwd"'s "realpath()" function to actually traverse the
         filesystem cleaning up paths like this.


Trying Cwd::realpath in your example (but with real filenames, because realpath() looks at the filesystem in order to resolve symlinks) gives the result you seek. As a side issue, because realpath does look at the filesystem, it's expensive compared with the other operations, so you may want to avoid it if you can.

(As far as reporting bugs goes, if you suspect a bug in any component of the "perl core" -- that is, a file that's part of the perl distribution tarball that you download from perl.org or wherever -- you should report it using the perlbug application that is part of the distribution. On the other hand, if the suspected bug's in a module that is not part of the perl core, you need to mail the maintainer of the module about the problem. You can find out who the maintainer is by going to http://search.cpan.org, or by using the CPAN module -- for example

$ perl -MCPAN -eshell

cpan shell -- CPAN exploration and modules installation (v1.7601)
ReadLine support enabled

cpan> m Acme::EyeDrops
CPAN: Storable loaded ok
Going to read /Users/domo/.cpan/Metadata
  Database was generated on Sat, 10 Dec 2005 02:59:06 GMT
Module id = Acme::EyeDrops
    CPAN_USERID  ASAVIGE (Andrew J. Savige <[EMAIL PROTECTED]>)
    CPAN_VERSION 1.51
    CPAN_FILE    A/AS/ASAVIGE/Acme-EyeDrops-1.51.tar.gz
    INST_FILE    (not installed)


cpan>

In your case, as File::Spec's a perl core module, you'd use perlbug if there was a real bug.)
--
Dominic Dunlop

Reply via email to