Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 03, 2017 std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Attachments:
| From the manual page on std.path.buildPath:
writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz"
writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz"
writeln(buildPath("/foo", "/bar")); // "/bar"
I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff.
"If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped."
I cannot find any excuse for this to be even remotely reasonable.
--
Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
|
June 03, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On 2017-06-03 16:12, Russel Winder via Digitalmars-d-learn wrote: > From the manual page on std.path.buildPath: > > writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz" > writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz" > writeln(buildPath("/foo", "/bar")); // "/bar" > > I have no idea what drugs the person who chose that last one to be > correct semantics was on at the time, but it was some seriously bad > stuff. > > "If any of the path segments are absolute (as defined by isAbsolute), > the preceding segments will be dropped." > > I cannot find any excuse for this to be even remotely reasonable. Unfortunately it's been like this since forever. I mean, I checked the git history, it's been like this for as long as we have history, including when it was called "join". -- /Jacob Carlborg |
June 03, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 3 June 2017 at 14:12:03 UTC, Russel Winder wrote: > I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff. Of all people, I certainly didn't expect you to stray so far from the tone appropriate here. Please keep it civil. > I cannot find any excuse for this to be even remotely reasonable. I suspect the original author had applications in mind where you want to resolve user-specified file system paths that might be relative or absolute. One could just use buildPath to prepend the root path if necessary. (Whether this is useful or just unnecessarily error-prone is another question, of course.) — David |
June 04, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 3 June 2017 at 14:12:03 UTC, Russel Winder wrote:
> From the manual page on std.path.buildPath:
>
> writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz"
> writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz"
> writeln(buildPath("/foo", "/bar")); // "/bar"
>
> I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff.
>
> "If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped."
>
> I cannot find any excuse for this to be even remotely reasonable.
What is your expected behavior? Throw an exception? You can't really append an absolute path to another.
|
June 04, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On 2017-06-04 07:44, Jesse Phillips wrote: > What is your expected behavior? Throw an exception? You can't really > append an absolute path to another. Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves. -- /Jacob Carlborg |
June 04, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Sunday, 4 June 2017 at 15:56:58 UTC, Jacob Carlborg wrote:
> On 2017-06-04 07:44, Jesse Phillips wrote:
>
>> What is your expected behavior? Throw an exception? You can't really
>> append an absolute path to another.
>
> Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves.
buildPath("/usr/bin", "/usr/bin/gcc")
/usr/bin/usr/bin/gcc is obviously wrong. I think the semantic is not as illogical as it seem at first glance.
|
June 04, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote: > On 2017-06-04 07:44, Jesse Phillips wrote: > > > What is your expected behavior? Throw an exception? You can't > > really > > append an absolute path to another. > > Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves. And Python, Groovy, Java, Kotlin, Ceylon, C++, … -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
June 04, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Schluter | On 2017-06-04 19:05, Patrick Schluter wrote: > buildPath("/usr/bin", "/usr/bin/gcc") > > /usr/bin/usr/bin/gcc is obviously wrong. Says who? It might be exactly what I want. The case that came up is inside DStep. The user provides a set of files C header to be translated to D modules. The user also provides a flag to indicate where to place the resulting files. I wanted to be able to keep the existing directory structure of the header files in the new target location. Example: dstep -o result /usr/include/libxml2/libxml/*.h The internals of DStep will do something like: buildPath("result", "/usr/include/libxml2/libxml"); Which currently results in "/usr/include/libxml2/libxml". The end result is that DStep will try to write a file to "/usr/include/libxml2/libxml", which the user most likely will not have access to (without using sudo). I expected the result of buildPath to be "result/usr/include/libxml2/libxml". -- /Jacob Carlborg |
June 11, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote:
> On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote:
>> On 2017-06-04 07:44, Jesse Phillips wrote:
>>
>> > What is your expected behavior? Throw an exception? You can't
>> > really
>> > append an absolute path to another.
>>
>> Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves.
>
> And Python, Groovy, Java, Kotlin, Ceylon, C++, …
Python 3.5.1 on my machine:
>>> os.path.join("/asdf", "/bcd")
'/bcd'
>>> os.path.join("asdf", "/bcd")
'/bcd'
|
June 12, 2017 Re: std.path.buildPath | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ryan Frame Attachments:
| On Sun, 2017-06-11 at 13:21 +0000, Ryan Frame via Digitalmars-d-learn wrote: > On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote: > > On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote: > > > On 2017-06-04 07:44, Jesse Phillips wrote: > > > > > > > What is your expected behavior? Throw an exception? You can't > > > > really > > > > append an absolute path to another. > > > > > > Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves. > > > > And Python, Groovy, Java, Kotlin, Ceylon, C++, … > > Python 3.5.1 on my machine: > > >>> os.path.join("/asdf", "/bcd") > '/bcd' > >>> os.path.join("asdf", "/bcd") > '/bcd' ####### #### you are absolutely right, and it is clearly stated in the documentation that this is the expected behaviour. Clearly, I have never tried doing that in 20 years of playing with Python. And it has never come up in 12 years of running Python workshops! This behaviour is reinforced by pathlib which is the modern way of doing paths in Python, replacing os.path: import pathlib p = pathlib.Path() p = p.joinpath('/', 'usr', '/local', '/bin') print(p) result /bin. So given Python is one of the targets for D, consistency of behaviour implies D is currently doing the right thing. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
Copyright © 1999-2021 by the D Language Foundation