Skip to content

Commit

Permalink
Insert lock while reading from the installed map
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Aug 5, 2024
1 parent a945e56 commit 3468bdc
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) {

Check failure on line 339 in v2/pkgs/tools.go

View workflow job for this annotation

GitHub Actions / check-style (./)

exported method Tools.GetInstalledValue should have comment or be unexported
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 3468bdc

Please sign in to comment.