From 3468bdca7b019be1ebf2f27fe85540f9de30e734 Mon Sep 17 00:00:00 2001 From: MatteoPologruto Date: Mon, 5 Aug 2024 17:37:40 +0200 Subject: [PATCH] Insert lock while reading from the installed map --- v2/pkgs/tools.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/v2/pkgs/tools.go b/v2/pkgs/tools.go index c84d207f..379b7a52 100644 --- a/v2/pkgs/tools.go +++ b/v2/pkgs/tools.go @@ -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) @@ -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 {