Skip to content
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

cmd/go: "go version" fails if CWD is deleted #34499

Open
dotaheor opened this issue Sep 24, 2019 · 5 comments

Comments

@dotaheor
Copy link

commented Sep 24, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

true

What did you do?

$ cd /tmp
$ mkdir aaa
$ cd aaa
$ go version
go version go1.13 linux/amd64
$ rmdir ../aaa
$ go version
2019/09/24 11:26:36 cannot determine current directory: getwd: no such file or directory
$ which go
sh: 0: getcwd() failed: No such file or directory
/home/myname/go-sdk/bin/go

What did you expect to see?

go version should be unrelated to CWD.

What did you see instead?

go version needs to confirm CWD.

@mvdan

This comment has been minimized.

Copy link
Member

commented Sep 24, 2019

How realistic is this scenario? I agree that technically this should work, but in practice cmd/go does quite a bit of work at init time, before the main function or the version command are run. This includes getting the current working directory.

I assume this helps keep the global simpler, as one can rely on base.Cwd to be valid. We could move the error check out of init and into each of the uses of Cwd, perhaps turning it into a function like base.Cwd() that would run os.Getwd the first time it's called instead of at init time.

I'm just not convinced that this is worth the effort. For example, do we want to add cmd/go tests where the current directory has been removed?

/cc @bcmills @jayconrod

@mvdan mvdan added the NeedsDecision label Sep 24, 2019
@bcmills bcmills added this to the Unplanned milestone Sep 24, 2019
@bcmills bcmills added the NeedsFix label Sep 24, 2019
@bcmills

This comment has been minimized.

Copy link
Member

commented Sep 24, 2019

I think it would be fine to accept a fix for this, provided that the fix is not too invasive in practice, but I do not plan to fix it myself.

@AndersonQ

This comment has been minimized.

Copy link
Contributor

commented Sep 25, 2019

I was trying to reproduce and investigate, but I cannot. It might be platform/shell specific

###What version of Go are you using (go version)?
$ go version
go version go1.13 darwin/amd64

What did you do?

$ cd /tmp
$ mkdir aaa
$ cd aaa
$ go version
go version go1.13 darwin/amd64
$ rmdir ../aaa
$ go version
go version go1.13 darwin/amd64

It works on both zsh and bash for me

@bcmills

This comment has been minimized.

Copy link
Member

commented Sep 25, 2019

@AndersonQ, note that the original report was on linux. The filesystem on darwin platforms tends to behave differently.

@hasitpbhatt

This comment has been minimized.

Copy link
Contributor

commented Sep 26, 2019

I think it would be fine to accept a fix for this, provided that the fix is not too invasive in practice, but I do not plan to fix it myself.

The question here is, do we really want to go for a global singleton route?
Because in principle, Cwd should not be initialized unless it is needed, but adding a singleton will open up lock(multi-threads?), singleton abuse and all sorts of other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.