Skip to content

Commit fb06ef3

Browse files
Insert lock while reading from the installed map (#987)
1 parent a945e56 commit fb06ef3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

v2/pkgs/tools.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (t *Tools) Install(ctx context.Context, payload *tools.ToolPayload) (*tools
188188
key := correctTool.Name + "-" + correctTool.Version
189189
// Check if it already exists
190190
if t.behaviour == "keep" && pathExists(t.folder) {
191-
location, ok := t.installed[key]
191+
location, ok := t.getInstalledValue(key)
192192
if ok && pathExists(location) {
193193
// overwrite the default tool with this one
194194
err := t.writeInstalled(path)
@@ -336,6 +336,13 @@ func (t *Tools) SetBehaviour(behaviour string) {
336336
t.behaviour = behaviour
337337
}
338338

339+
func (t *Tools) getInstalledValue(key string) (string, bool) {
340+
t.mutex.RLock()
341+
defer t.mutex.RUnlock()
342+
location, ok := t.installed[key]
343+
return location, ok
344+
}
345+
339346
func pathExists(path string) bool {
340347
_, err := os.Stat(path)
341348
if err == nil {

0 commit comments

Comments
 (0)