diff --git a/src/cmd/go/internal/toolchain/toolchain.go b/src/cmd/go/internal/toolchain/toolchain.go index ab03fbe4ff..757ab6977d 100644 --- a/src/cmd/go/internal/toolchain/toolchain.go +++ b/src/cmd/go/internal/toolchain/toolchain.go @@ -7,6 +7,7 @@ package toolchain import ( "context" + "errors" "fmt" "go/build" "io/fs" @@ -22,7 +23,6 @@ import ( "cmd/go/internal/base" "cmd/go/internal/cfg" "cmd/go/internal/gover" - "cmd/go/internal/modcmd" "cmd/go/internal/modfetch" "cmd/go/internal/modload" "cmd/go/internal/run" @@ -410,22 +410,21 @@ func SwitchTo(gotoolchain string) { // Download and unpack toolchain module into module cache. // Note that multiple go commands might be doing this at the same time, // and that's OK: the module cache handles that case correctly. - m := &modcmd.ModuleJSON{ + m := module.Version{ Path: gotoolchainModule, Version: gotoolchainVersion + "-" + gotoolchain + "." + runtime.GOOS + "-" + runtime.GOARCH, } - modcmd.DownloadModule(context.Background(), m) - if m.Error != "" { - if strings.Contains(m.Error, ".info: 404") { + dir, err := modfetch.Download(context.Background(), m) + if err != nil { + if errors.Is(err, fs.ErrNotExist) { base.Fatalf("download %s for %s/%s: toolchain not available", gotoolchain, runtime.GOOS, runtime.GOARCH) } - base.Fatalf("download %s: %v", gotoolchain, m.Error) + base.Fatalf("download %s: %v", gotoolchain, err) } // On first use after download, set the execute bits on the commands // so that we can run them. Note that multiple go commands might be // doing this at the same time, but if so no harm done. - dir := m.Dir if runtime.GOOS != "windows" { info, err := os.Stat(filepath.Join(dir, "bin/go")) if err != nil {