Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: / absolute / realpath are broken

by Anonymous Monk
on Aug 18, 2013 at 07:48 UTC ( #1049892=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: but those aren't equivalent (C: is chdir C: && echo %cd% )

This breaks absolute and realpath (resolve)

$ perl -MPath::Tiny -le " print path( 'C:/')->realpath " C:/Documents and Settings/username $ perl -MPath::Tiny -le " print path( 'D:/')->realpath " D:/dev/misc $ perl -MPath::Tiny -le " print path( 'C:/')->absolute->realpath " D:/dev/misc/C:: No such file or directory at C:/perl/site/lib/Path/Tin +y.pm line 449. $ mversion Path::Tiny 0.028

Editing sub path to comment out the following line seems to fix it :)

$path =~ s{/$}{} if $path ne "/"; # hack to make splitpath give us a b +asename

There are 2 extra failures as a result of this patch (meaning its working)

not ok 55 - path('A:/') # Failed test 'path('A:/')' # at t/zzz-spec.t line 200. # got: 'A:/' # expected: 'A:' not ok 67 - path('A:/') # Failed test 'path('A:/')' # at t/zzz-spec.t line 200. # got: 'A:/' # expected: 'A:'

Does this break on linux?

Comment on Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: / absolute / realpath are broken
Select or Download Code
Re: Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: / absolute / realpath are broken
by vsespb (Hermit) on Aug 18, 2013 at 09:04 UTC
    Does this break on linux?
    No
Re: Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: / absolute / realpath are broken
by tobyink (Abbot) on Aug 18, 2013 at 10:29 UTC

    It doesn't break the test suite, but I don't know whether it breaks any usage patterns that aren't tested by the test suite.

    Report your problem and suggested solution to the issue tracker - David Golden is pretty quick on the ball for Path::Tiny issues.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Path-Tiny-0.028 Path::Tiny on win32 turns C:/ or C:\ into C: / absolute / realpath are broken
by xdg (Monsignor) on Aug 19, 2013 at 10:49 UTC

    FYI: This has been opened as issue #49.

    Does this break on Linux

    It should. So that's a test suite coverage failure.

    I think I have a fix, but I have a broader question:

    Is there any reason to allow a raw volume like "C:" (no trailing slash) or "\\server\share" as a Path::Tiny "path"? Or should I be fixing those to have a trailing slash so they are properly understood as referencing the root directory of those volumes?

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I would say that there is a misconception. C: does not reference the root directory of a volume. It references the current working directory of that volume.

      You should either prohibit this or handle it properly, not silently convert to something else, especially not a root directory. I think the failure mode of converting C: to C:/ is a very bad one:

      my $p= path("C:"); unlink $_ for $p->children;

      For UNC paths, I see no such bad failure mode of appending a trailing directory separator.

        C: does not reference the root directory of a volume

        I understand that. What I'm trying to get guidance on is how likely it is that people would use "C:" and not mean the root directory.

        If I understand you correctly, what probably needs to happen is to immediately turn C: into the absolute path for cwd on that volume via getdcwd.

        Is that right?

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1049892]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-08-30 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls