Skip to content

Commit

Permalink
fix: avoid concurrent access to the global map (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Apr 10, 2023
1 parent 3ed86aa commit 009675c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/downloader/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

getter "github.com/hashicorp/go-getter"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"
)

Expand Down Expand Up @@ -34,16 +35,19 @@ 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{
Ctx: ctx,
Src: src,
Dst: dst,
Pwd: pwd,
Getters: getter.Getters,
Getters: getters,
Mode: getter.ClientModeAny,
Options: opts,
}
Expand Down

0 comments on commit 009675c

Please sign in to comment.