Skip to content

Commit

Permalink
Insert lock while reading from the installed map (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto authored Aug 5, 2024
1 parent a945e56 commit fb06ef3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (t *Tools) Install(ctx context.Context, payload *tools.ToolPayload) (*tools
key := correctTool.Name + "-" + correctTool.Version
// Check if it already exists
if t.behaviour == "keep" && pathExists(t.folder) {
location, ok := t.installed[key]
location, ok := t.getInstalledValue(key)
if ok && pathExists(location) {
// overwrite the default tool with this one
err := t.writeInstalled(path)
Expand Down Expand Up @@ -336,6 +336,13 @@ func (t *Tools) SetBehaviour(behaviour string) {
t.behaviour = behaviour
}

func (t *Tools) getInstalledValue(key string) (string, bool) {
t.mutex.RLock()
defer t.mutex.RUnlock()
location, ok := t.installed[key]
return location, ok
}

func pathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
Expand Down

0 comments on commit fb06ef3

Please sign in to comment.