Skip to content

Improve installed.json handling in v2/tools #983

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

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use the correct lock for reading and writing
  • Loading branch information
MatteoPologruto committed Aug 5, 2024
commit 1a36a2bb610c3906e30f3430fd20aacd70c6b503
8 changes: 4 additions & 4 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ func rename(base string) extract.Renamer {
}

func (t *Tools) readInstalled() error {
t.mutex.Lock()
defer t.mutex.Unlock()
t.mutex.RLock()
defer t.mutex.RUnlock()
// read installed.json
installedFile, err := utilities.SafeJoin(t.folder, "installed.json")
if err != nil {
Expand All @@ -305,8 +305,8 @@ func (t *Tools) readInstalled() error {
}

func (t *Tools) writeInstalled(path string) error {
t.mutex.RLock()
defer t.mutex.RUnlock()
t.mutex.Lock()
defer t.mutex.Unlock()

parts := strings.Split(path, string(filepath.Separator))
tool := parts[len(parts)-2]
Expand Down