On Sunday, 28 July 2013 at 21:09:55 UTC, Lars T. Kyllingstad wrote:
Currently, std.path.buildPath() is designed so that if one of the path segments is rooted, then the preceding segments are simply dropped. That is,

   assert(buildPath("foo", "bar", "/baz") == "/baz");

The only reason I wrote it like this is that this was how the old (now deprecated and removed) join() function was designed, and buildPath() was supposed to be a drop-in replacement.

I have come to think this design sucks, and I want to fix it. I cannot think of a single use case for it. I have a new implementation of this function in the pipeline, so now seems like a good time. Would anyone be opposed to me rewriting it so that it throws an exception when any path segment but the first is rooted?

I use this feature to concatenate path fragments where one of them might be an absolute path (in which case they override the previous ones). absolutePath requires that the base path is absolute, a requirement that buildPath doesn't have.

Personally, I think that the current behavior of buildPath makes sense. Leading directory separators should not be present in arguments passed to buildPath unless they indicate an absolute path.

My recommendation to resolve the problem is to expand and point out this behavior in the documentation.

Reply via email to