-
Notifications
You must be signed in to change notification settings - Fork 18k
path/filepath: document that filepath.Join("c:", "a") returns c:\a
not c:a
on Windows
#11551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
No... See code: |
Related discussion with more details: https://groups.google.com/forum/#!topic/golang-nuts/xFWpetTOPp4 |
@xiofen I am no good at writing documentation. So, if you feel strongly about it, suggest you own change - http://golang.org/doc/contribute.html Thank you. Alex |
I agree |
Perhaps "adding a separator if one is not already present" |
@minux and me disagree about https://go-review.googlesource.com/#/c/11882 change. We need more reviewers to lean us one way or the other. Please help. Thank you. Alex |
Although I do think the new behaviour is better, I also think this is a breaking change. So this should be a no-go for Go1.x. |
I don't see a clear justification for the change in CL 11882. I see the logic in it, but the function was never documented to work that way, and it could clearly break existing programs. I think we should document the current behavior, as this issue suggests. |
Intuitively, I see filepath.Join as giving the path you would get if you did a Chdir to each path in sequence (without looking at the filesystem, so you could end up with a relative path). On Windows if I Chdir("c:") and then Chdir("abc") I end up in the same place as if I did Chdir("c:abc"). This is different from Chdir("c:\abc") because on Windows you have a working directory for each drive letter. I don't have any valid intuition about the current behavior. It strikes me as just a symbol manipulation that makes Unix-specific assumptions even though filepath is supposed to be a cross platform module. Although it could break existing code, I suspect any such existing code is already buggy, and this change would make it less buggy. |
@mattharden, the intuition is wrong if there is .. in the sequence
and symlinks are involved.
And indeed, filepath.Join is just symbolic manipulation. You can
imagine that we implement filepath.Join in a way you described
(chdir into each element, and then return the current directory),
but that's not how filepath.Join currently works.
I wouldn't call existing code as buggy. People might look at our
test cases and assume that filepath.Join("C:", "Windows")
returning "C:\Windows" is the expected behavior of filepath.Join
and then rely on that. If we don't have such a test case, then
perhaps we can argue that it's unintended behavior. But with
that test case, I don't think we can call the behavior buggy as
we basically told people it's the intention.
|
Thanks to everyone for their input. It seems to me I don't have support for my change. I just want to clarify my reasoning (before I abandon my change). With this code:
If "a" contains absolute path (filepath.IsAbd(a) returns true), should I expect "b" to contain absolute path? If "a" contains relative path (filepath.IsAbd(a) returns false), should I expect "b" to contain relative path? The answers to these questions are "yes" on unix. Not so on windows. This program http://play.golang.org/p/_DOiToc8cD prints:
I think that this invariant is important. If only because Go team developers (none of who use windows) assume that invariant is there. So no amount of documenting will stop them (and others) from making mistakes. Alex |
@alexbrainman To be clear, I agree with your rationale, and if we were designing this function now, that is how it should work. But that's not the question we are facing. The question is: given that the function has behaved as it presently does since before the Go 1 release, should we change it? The current behaviour is meaningful, is not always wrong, and is easy to avoid if you know about it. Given that, it's hard for me to support a change that may silently break some currently working programs. |
If the interface is like below, I agree with your opinion.
But this is
So I'm thinking this is right. |
c:\a
not c:a
on Windows
CL https://golang.org/cl/17198 mentions this issue. |
CL https://golang.org/cl/17470 mentions this issue. |
CL https://golang.org/cl/17620 mentions this issue. |
EvalSymlinks code assumes that Join has a bug (see issue #11551 for details). But issue #11551 has been fixed. Remove the workaround so it does not confuses us when we read code next time. Change-Id: I06bea20189f01f9922237c05516847353d8e4736 Reviewed-on: https://go-review.googlesource.com/17620 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This program:
displays:
but should display:
or
Alex
The text was updated successfully, but these errors were encountered: