[phobos] RFC: std.path

Lars Tandle Kyllingstad lars at kyllingen.net
Wed Jun 15 01:16:57 PDT 2011


On Tue, 2011-06-14 at 23:09 +0200, Rainer Schuetze wrote:
> On 08.06.2011 21:29, Lars Tandle Kyllingstad wrote:
> > As you may already know, I've had a new version of std.path in the works
> > for a while.  It is ready now, and I am waiting for my turn in the
> > review queue in the main NG.  In the meantime, I just thought I'd run it
> > by this mailing list to iron out the worst wrinkles.
> >
> > So, if you feel like it, please comment.
> >
> > Code:
> > https://github.com/kyllingstad/phobos/blob/std-path/std/path.d
> >
> > Docs:
> > http://www.kyllingen.net/code/new-std-path/phobos-prerelease/std_path.html
> >
> >
> > -Lars
> 
> Looks good to me. A few notes:
> 
> - I agree with Jose that toAbsolute and expandTilde feel a little 
> out-of-place in this module as they are not only string manipulation 
> functions.

In principle, I agree, but I can't think of a better module in which to
put them.


> - expandTilde is currently not implemented on windows, but I think a 
> similar functionality using environment variables similar to HOME could 
> work, too. I have no idea how to implement it for other users than the 
> current, though.

The problem is that tilde expansion is a non-existent concept on
Windows.  And as torhu points out, it is far from obvious which
directory should be used.  Case in point:

http://technet.microsoft.com/en-us/library/cc749104(WS.10).aspx

*Shudder*...  I think adding an expandEnvironmentVars() function to
std.process would be a better idea.


> - \\network drives are currently only respected under windows (at least 
> that's what the documentation says). At work I'm using the same syntax 
> on OSX to mount network drives (with forward slashes), so I guess it is 
> also valid on Posix systems.

I have noted that "//" is treated specially in the POSIX specification,
but I have never actually seen it in use.  This, naturally, led me to
believe that nobody uses it. ;)  Thanks for proving me wrong!

Fortunately, I believe my current implementation handles it quite
nicely.  I may have to make a small change to toCanonical() so it
doesn't collapse two leading slashes, but that's about it, I think.


> - isRelative and isAbsolute both return false on the empty string, while 
> dirName("") returns ".". Wouldn't that imply that isRelative("") is true?

Maybe. :)  What do others think?


> - when transferring data containing file names between different 
> operating systems, it would be convenient to have the path operation of 
> the other system available, too. While you can deal with posix file 
> names on windows without big problems, the reverse is usually not the 
> case (you have to convert backslashes manually, don't know how to strip 
> drive names, etc). Would it be a good idea to have both versions 
> accessible through namespaces, e.g. Posix.isRooted() and Win.isRooted(), 
> and let the global functions dispatch to the implementation that fits 
> the current OS?

Alas, I suggested this a while ago, but it was shot down.  I even wrote
a pretty elegant proof-of-concept implementation of it, if I may say so
myself (note in particular lines 167-168):

https://github.com/kyllingstad/ltk/blob/64b1c895fdb8b84181398c8d367ad1534e7f05c1/ltk/path.d

The ensuing discussion (this list, April 2010) can be found here:

http://lists.puremagic.com/pipermail/phobos/2010-April/thread.html#306

I still think it is a good idea, though.

-Lars



More information about the phobos mailing list