digitalmars.D - buildPath() and absolute paths
- Lars T. Kyllingstad (13/13) Jul 28 2013 Currently, std.path.buildPath() is designed so that if one of the path
- Jonathan M Davis (4/19) Jul 28 2013 Well, it would potentially break code, but it would as far as I can tell...
- Vladimir Panteleev (12/25) Jul 28 2013 I use this feature to concatenate path fragments where one of
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? Lars
Jul 28 2013
On Sunday, July 28, 2013 23:09:53 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?Well, it would potentially break code, but it would as far as I can tell, it would only break code which is buggy. So, I don't see a problem with it. - Jonathan M Davis
Jul 28 2013
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.
Jul 28 2013