Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 18 additions & 5 deletions newt/syscfg/syscfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,33 @@ func ResolveValueRefName(val string) string {
}

func (cfg *Cfg) ExpandRef(val string) (string, string, error) {
var visited []string
var entry CfgEntry
var ok bool

refName := ResolveValueRefName(val)
if refName == "" {
// Not a reference.
return "", val, nil
}

entry, ok := cfg.Settings[refName]
if !ok {
return "", "", util.FmtNewtError(
"setting value \"%s\" references undefined setting", val)
for refName != "" {
entry, ok = cfg.Settings[refName]
if !ok {
return "", "", util.FmtNewtError(
"setting value \"%s\" references undefined setting", val)
}
for _, v := range visited {
if entry.Name == v {
return "", "", util.FmtNewtError(
"setting value \"%s\" creates a reference loop", entry.Name)
}
}
visited = append(visited, entry.Name)
refName = ResolveValueRefName(entry.Value)
}

return entry.Name, entry.Value, nil

}

func (cfg *Cfg) AddInjectedSettings() {
Expand Down
3 changes: 1 addition & 2 deletions newt/val/valsetting.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func (vs *ValSetting) IntVal() (int, error) {
func ResolveValSetting(s string, cfg *syscfg.Cfg) (ValSetting, error) {
refName, val, err := cfg.ExpandRef(s)
if err != nil {
return ValSetting{},
util.FmtNewtError("value \"%s\" references undefined setting", s)
return ValSetting{}, err
}

return ValSetting{
Expand Down
Loading