From a440499741faaedf78d23141972bf6258b29a8d0 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Mon, 10 Apr 2023 09:20:14 +0300 Subject: [PATCH] fix: avoid concurrent access to the global map --- pkg/downloader/download.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/downloader/download.go b/pkg/downloader/download.go index b97f681d7e10..0c9388248a6d 100644 --- a/pkg/downloader/download.go +++ b/pkg/downloader/download.go @@ -5,6 +5,7 @@ import ( "os" getter "github.com/hashicorp/go-getter" + "golang.org/x/exp/maps" "golang.org/x/xerrors" ) @@ -34,8 +35,11 @@ func Download(ctx context.Context, src, dst, pwd string) error { var opts []getter.ClientOption + // Clone the global map so that it will not be accessed concurrently. + getters := maps.Clone(getter.Getters) + // Overwrite the file getter so that a file will be copied - getter.Getters["file"] = &getter.FileGetter{Copy: true} + getters["file"] = &getter.FileGetter{Copy: true} // Build the client client := &getter.Client{ @@ -43,7 +47,7 @@ func Download(ctx context.Context, src, dst, pwd string) error { Src: src, Dst: dst, Pwd: pwd, - Getters: getter.Getters, + Getters: getters, Mode: getter.ClientModeAny, Options: opts, }