dirlist: prevent race condition on accessing uiconfig

Prevent a race condition when accessing UI Config maps

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-09-26 18:26:35 -05:00 committed by Robin Jarry
parent 4e84df4a28
commit 83136234a4

View file

@ -8,6 +8,7 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
@ -48,6 +49,7 @@ type DirectoryLister interface {
type DirectoryList struct { type DirectoryList struct {
ui.Invalidatable ui.Invalidatable
sync.Mutex
Scrollable Scrollable
aercConf *config.AercConfig aercConf *config.AercConfig
acctConf *config.AccountConfig acctConf *config.AccountConfig
@ -90,6 +92,8 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
} }
func (dirlist *DirectoryList) UiConfig(dir string) *config.UIConfig { func (dirlist *DirectoryList) UiConfig(dir string) *config.UIConfig {
dirlist.Lock()
defer dirlist.Unlock()
if dir == "" { if dir == "" {
dir = dirlist.Selected() dir = dirlist.Selected()
} }