develooper Front page | perl.perl5.porters | Postings from February 2008

RE: MM_Win32.t failures (caused by PathTools upgrade)

Thread Previous | Thread Next
Steve Hay
February 1, 2008 04:59
RE: MM_Win32.t failures (caused by PathTools upgrade)
Message ID:
Michael G Schwern wrote:
> Steve Hay wrote:
>>> Can you check what File::Spec->canonpath("C:trick\dir\now_OK") does?
>> Ick. You didn't mean that: you meant check what
>> File::Spec->canonpath('C:trick\dir\now_OK') does, and the answer is
>> nothing: 
>> C:\p5p\bleadperl>.\perl -MFile::Spec -e "print
>> File::Spec->canonpath('C:trick\dir\now_OK')"
>> C:trick\dir\now_OK
> Oh, I was thinking wrong.  MakeMaker is doing the right thing,
> meaning it's just doing what File::Spec does.  MakeMaker can be
> removed from consideration as part of the bug.  MakeMaker's test is
> wrong and should be using catpath(). 

OK. Someone needs to change the test script, then. I'll look when I find
time if no-one else has done by then.

>>> Probably use a blank directory to represent root.  That's what Unix
>>> does.  Try: 
>>> catdir( 'c:', '', 'trick', 'dir' );
>> No good either:
>> C:\p5p\bleadperl>.\perl -MFile::Spec -e "print
>> File::Spec->catdir('C:', '', 'trick', 'dir')" C:trick\dir
> Thinking more about this, it probably shouldn't work given that
> catdir() is treating C: as a directory so you're asking for a root
> directory in the middle of the path which doesn't make any sense.
> catpath() is the correct thing to use.


>>> Actually the correct answer is "none of the above" because catdir()
>>> uses directories, not volumes.  In reality the correct thing to use
>>> is catpath().
>> It's still confusing:
>> C:\p5p\bleadperl>.\perl -MFile::Spec -e "print
>> File::Spec->catpath('C:', 'trick', 'file')" C:trick\file
>> C:\p5p\bleadperl>.\perl -MFile::Spec -e "print
>> File::Spec->catpath('C:\\', 'trick', 'file')"
>> C:\trick\file
>  >
>> In other words catpath() expects the $volume to be something like C:\
>> rather than just C:, which is at odds with splitpath() which returns
>> the $volume as just C: 
>> C:\p5p\bleadperl>.\perl -MFile::Spec -e "print
>> +(File::Spec->splitpath('C:\trick\file'))[0]"
>> C:
> This is all correct.  splitpath() returns ($volume, $directories,
> $file) so the return value should be:
> ("C:", "\trick\", "file")

Ah, right. So going back to the original examples, we actually want
something like this:

my @path_eg = qw( c: /trick/ dir/now_OK );
print catpath(@path_eg);

> It's arguable whether the volume name should be "C" or "C:".  Depends
> on whether or not : is considered part of the volume name or just the
> volume separator.
> Try this:
> print join "\n", File::Spec->splitpath('C:\trick\file');
> print File::Spec->catpath("C:", File::Spec->catdir("", "trick"),
> "file"); 
> It should say:
> C:
> \trick\
> file
> C:\trick\file

Yes (except that you missed a newline between your print()s).

Thanks for the explanations.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About