From c91b40729c90ad8648a4a802f945c2c40a83310a Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Tue, 27 Apr 2021 14:50:30 +0200 Subject: [PATCH 1/2] use stricter mutex policy to prevent installed.json corruption --- tools/tools.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tools.go b/tools/tools.go index 88ef425ea..e1e66a51d 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -101,9 +101,9 @@ func (t *Tools) GetLocation(command string) (string, error) { // writeMap() writes installed map to the json file "installed.json" func (t *Tools) writeMap() error { - t.mutex.RLock() + t.mutex.Lock() b, err := json.Marshal(t.installed) - t.mutex.RUnlock() + defer t.mutex.Unlock() if err != nil { return err } From 8055452c51ff9c0e85d7770a9c3f515bed24e835 Mon Sep 17 00:00:00 2001 From: umbynos Date: Thu, 29 Apr 2021 12:19:02 +0200 Subject: [PATCH 2/2] move locking before installed.json read --- tools/tools.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tools.go b/tools/tools.go index e1e66a51d..53892b22a 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -113,13 +113,13 @@ func (t *Tools) writeMap() error { // readMap() reads the installed map from json file "installed.json" func (t *Tools) readMap() error { + t.mutex.Lock() + defer t.mutex.Unlock() filePath := path.Join(dir(), "installed.json") b, err := ioutil.ReadFile(filePath) if err != nil { return err } - t.mutex.Lock() - defer t.mutex.Unlock() return json.Unmarshal(b, &t.installed) }