diff --git a/internal/configfile/config_file.go b/internal/configfile/config_file.go index 4ac1956f..971871af 100644 --- a/internal/configfile/config_file.go +++ b/internal/configfile/config_file.go @@ -4,6 +4,7 @@ import ( "errors" "path/filepath" "strings" + "sync" "github.com/BurntSushi/toml" "github.com/qiniu/go-sdk/v7/internal/env" @@ -18,6 +19,7 @@ type profileConfig struct { var ( profileConfigs map[string]*profileConfig + profileConfigsMutex sync.Mutex ErrInvalidBucketUrl = errors.New("invalid bucket url") ) @@ -79,6 +81,9 @@ func getProfile() (*profileConfig, error) { } func load() error { + profileConfigsMutex.Lock() + defer profileConfigsMutex.Unlock() + if profileConfigs != nil { return nil }