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: tool locates go.mod file case-insensitively but uses lowercase in output #46204

Closed
adonovan opened this issue May 17, 2021 · 1 comment

Comments

@adonovan
Copy link
Member

adonovan commented May 17, 2021

The go command recognizes a go.mod file using a case-insensitive match, presumably to support file systems that do not preserve case. However, it does not retain the actual name of the file thus found, and later synthesizes a name by appending the canonical lowercase go.mod to the directory name. Example:

$ mkdir foo
$ cd foo
$ go mod init foo
go: creating new go.mod: module foo
$ mv go.mod gO.MoD
$ go list -m -json
{
	"Path": "foo",
	"Main": true,
	"Dir": "/Users/adonovan/w/foo",
	"GoMod": "/Users/adonovan/w/foo/go.mod",
	"GoVersion": "1.16"
}

Consequently, the GoMod file in the JSON output does not necessarily exist. Irregularly cased files thus pose an unexpected source of fragility in tools that process modules.

@adonovan
Copy link
Member Author

Today I learned that the Mac OS file system, despite its UNIXy feel, preserves case but uses case-insensitive match. Not sure how that escaped my attention for so long.

tmp$ echo foo > foo
tmp$ cat FOO
foo

So the filename in my first example is a valid alias for the actual go.mod file. On Linux, the go command does not recognize alternative casings of go.mod. So I think there is no problem here.

@golang golang locked and limited conversation to collaborators May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants