From 28a6f9cf2bccaabc69e7beb3d86161fa77f21daf Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Tue, 26 Jul 2022 14:43:48 +0800 Subject: [PATCH] cmd/go: add Context parameter to download function Updates #38714 Change-Id: Ie5c7761ec003f84e649fa4c90be184a5ff6a0879 Reviewed-on: https://go-review.googlesource.com/c/go/+/419554 Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Than McIntosh Reviewed-by: Joedian Reid Auto-Submit: Bryan Mills Reviewed-by: Dmitri Shuralyov --- src/cmd/go/internal/get/get.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go index 586427ff33d..02289bf7f46 100644 --- a/src/cmd/go/internal/get/get.go +++ b/src/cmd/go/internal/get/get.go @@ -170,7 +170,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { mode |= load.GetTestDeps } for _, pkg := range downloadPaths(args) { - download(pkg, nil, &stk, mode) + download(ctx, pkg, nil, &stk, mode) } base.ExitIfErrors() @@ -250,7 +250,7 @@ var downloadRootCache = map[string]bool{} // download runs the download half of the get command // for the package or pattern named by the argument. -func download(arg string, parent *load.Package, stk *load.ImportStack, mode int) { +func download(ctx context.Context, arg string, parent *load.Package, stk *load.ImportStack, mode int) { if mode&load.ResolveImport != 0 { // Caller is responsible for expanding vendor paths. panic("internal error: download mode has useVendor set") @@ -258,9 +258,9 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int) load1 := func(path string, mode int) *load.Package { if parent == nil { mode := 0 // don't do module or vendor resolution - return load.LoadImport(context.TODO(), load.PackageOpts{}, path, base.Cwd(), nil, stk, nil, mode) + return load.LoadImport(ctx, load.PackageOpts{}, path, base.Cwd(), nil, stk, nil, mode) } - return load.LoadImport(context.TODO(), load.PackageOpts{}, path, parent.Dir, parent, stk, nil, mode|load.ResolveModule) + return load.LoadImport(ctx, load.PackageOpts{}, path, parent.Dir, parent, stk, nil, mode|load.ResolveModule) } p := load1(arg, mode) @@ -403,7 +403,7 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int) if i >= len(p.Imports) { path = load.ResolveImportPath(p, path) } - download(path, p, stk, 0) + download(ctx, path, p, stk, 0) } if isWildcard {