Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert lock while reading from the installed map #987

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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