mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
create some unlocked methods for State
State.Init() needs to be called externally, so make sure it only calls unlocked internal methods once a lock is acquired.
This commit is contained in:
parent
90aab0105d
commit
e5ff4d5bd4
@ -128,6 +128,11 @@ func (s *State) children(path []string) []*ModuleState {
|
|||||||
func (s *State) AddModule(path []string) *ModuleState {
|
func (s *State) AddModule(path []string) *ModuleState {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
return s.addModule(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *State) addModule(path []string) *ModuleState {
|
||||||
// check if the module exists first
|
// check if the module exists first
|
||||||
m := s.moduleByPath(path)
|
m := s.moduleByPath(path)
|
||||||
if m != nil {
|
if m != nil {
|
||||||
@ -616,10 +621,10 @@ func (s *State) init() {
|
|||||||
if s.Version == 0 {
|
if s.Version == 0 {
|
||||||
s.Version = StateVersion
|
s.Version = StateVersion
|
||||||
}
|
}
|
||||||
if s.ModuleByPath(rootModulePath) == nil {
|
if s.moduleByPath(rootModulePath) == nil {
|
||||||
s.AddModule(rootModulePath)
|
s.addModule(rootModulePath)
|
||||||
}
|
}
|
||||||
s.EnsureHasLineage()
|
s.ensureHasLineage()
|
||||||
|
|
||||||
for _, mod := range s.Modules {
|
for _, mod := range s.Modules {
|
||||||
mod.init()
|
mod.init()
|
||||||
@ -634,6 +639,10 @@ func (s *State) EnsureHasLineage() {
|
|||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
s.ensureHasLineage()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *State) ensureHasLineage() {
|
||||||
if s.Lineage == "" {
|
if s.Lineage == "" {
|
||||||
s.Lineage = uuid.NewV4().String()
|
s.Lineage = uuid.NewV4().String()
|
||||||
log.Printf("[DEBUG] New state was assigned lineage %q\n", s.Lineage)
|
log.Printf("[DEBUG] New state was assigned lineage %q\n", s.Lineage)
|
||||||
@ -648,6 +657,10 @@ func (s *State) AddModuleState(mod *ModuleState) {
|
|||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
s.addModuleState(mod)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *State) addModuleState(mod *ModuleState) {
|
||||||
for i, m := range s.Modules {
|
for i, m := range s.Modules {
|
||||||
if reflect.DeepEqual(m.Path, mod.Path) {
|
if reflect.DeepEqual(m.Path, mod.Path) {
|
||||||
s.Modules[i] = mod
|
s.Modules[i] = mod
|
||||||
|
Loading…
Reference in New Issue
Block a user