aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
diff options
context:
space:
mode:
authorPhilipp Sauter <sauterp@protonmail.com>2020-11-08 22:12:38 +0100
committerBryan C. Mills <bcmills@google.com>2021-05-05 01:28:34 +0000
commit4df662fb373480b5055e645120558bb536fae42c (patch)
tree56e29e105f1f96e348060959b03ab4d49ea959b0 /src/cmd/go/internal/modload/init.go
parentbb5e45219af69135c389c6b68f9a67207bb32e05 (diff)
downloadgo-4df662fb373480b5055e645120558bb536fae42c.tar.gz
go-4df662fb373480b5055e645120558bb536fae42c.zip
cmd/go: don't crash when running "go version" in deleted directory
If the go command is executed on Linux in a deleted directory, it fails. This behavior is reasonable for commands which depend on the CWD, but it's unexpected for commands like `go version`. This change delays initialization of a global CWD variable. Fixed #34499 Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/268261 Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Bryan C. Mills <bcmills@google.com> Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r--src/cmd/go/internal/modload/init.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 99c0c2b981..5cdea12cd3 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -135,7 +135,7 @@ func Init() {
return
}
- if err := fsys.Init(base.Cwd); err != nil {
+ if err := fsys.Init(base.Cwd()); err != nil {
base.Fatalf("go: %v", err)
}
@@ -179,7 +179,7 @@ func Init() {
}
modRoot = ""
} else {
- modRoot = findModuleRoot(base.Cwd)
+ modRoot = findModuleRoot(base.Cwd())
if modRoot == "" {
if cfg.ModFile != "" {
base.Fatalf("go: cannot find main module, but -modfile was set.\n\t-modfile cannot be used to set the module root directory.")
@@ -276,7 +276,7 @@ func WillBeEnabled() bool {
return false
}
- if modRoot := findModuleRoot(base.Cwd); modRoot == "" {
+ if modRoot := findModuleRoot(base.Cwd()); modRoot == "" {
// GO111MODULE is 'auto', and we can't find a module root.
// Stay in GOPATH mode.
return false
@@ -335,8 +335,8 @@ func die() {
if cfg.Getenv("GO111MODULE") == "off" {
base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
}
- if dir, name := findAltConfig(base.Cwd); dir != "" {
- rel, err := filepath.Rel(base.Cwd, dir)
+ if dir, name := findAltConfig(base.Cwd()); dir != "" {
+ rel, err := filepath.Rel(base.Cwd(), dir)
if err != nil {
rel = dir
}
@@ -479,7 +479,7 @@ func loadModFile(ctx context.Context) (rs *Requirements, needCommit bool) {
// exactly the same as in the legacy configuration (for example, we can't get
// packages at multiple versions from the same module).
func CreateModFile(ctx context.Context, modPath string) {
- modRoot = base.Cwd
+ modRoot = base.Cwd()
Init()
modFilePath := ModFilePath()
if _, err := fsys.Stat(modFilePath); err == nil {
@@ -646,7 +646,7 @@ func initTarget(m module.Version) {
Target = m
targetPrefix = m.Path
- if rel := search.InDir(base.Cwd, cfg.GOROOTsrc); rel != "" {
+ if rel := search.InDir(base.Cwd(), cfg.GOROOTsrc); rel != "" {
targetInGorootSrc = true
if m.Path == "std" {
// The "std" module in GOROOT/src is the Go standard library. Unlike other