Prepare subtree filter prefixes once per discovery
This commit is contained in:
@@ -130,8 +130,13 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
||||
return configFailure("Configuration scope did not provide path metadata.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path discovery without metadata", name))
|
||||
}
|
||||
report := pathDiscoveryReport{Scope: name, Paths: []pathDiscoveryEntry{}}
|
||||
var prefix []string
|
||||
if plan.under != nil {
|
||||
prefix = pointerTokens(plan.under.String())
|
||||
}
|
||||
for _, path := range acquired.Value.Metadata.HistoricalPaths() {
|
||||
if plan.under != nil && !pathWithin(path, *plan.under) {
|
||||
pointer := path.String()
|
||||
if plan.under != nil && !pathWithin(pointer, prefix) {
|
||||
continue
|
||||
}
|
||||
info, present := acquired.Value.Metadata.Lookup(path)
|
||||
@@ -141,7 +146,7 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
||||
if present && plan.explicit.Set && info.Explicit != plan.explicit.Value {
|
||||
continue
|
||||
}
|
||||
entry := pathDiscoveryEntry{Path: path.String(), Present: present}
|
||||
entry := pathDiscoveryEntry{Path: pointer, Present: present}
|
||||
if present {
|
||||
entry.Metadata = &pathMetadata{Explicit: info.Explicit}
|
||||
}
|
||||
@@ -192,14 +197,15 @@ func runConfigExplanation[I, S any](invocation commandkit.Invocation, plan *conf
|
||||
return commandkit.Success()
|
||||
}
|
||||
|
||||
func pathWithin(path, parent configkit.Path) bool {
|
||||
tokens := func(value string) []string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return strings.Split(strings.TrimPrefix(value, "/"), "/")
|
||||
func pointerTokens(value string) []string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
child, prefix := tokens(path.String()), tokens(parent.String())
|
||||
return strings.Split(strings.TrimPrefix(value, "/"), "/")
|
||||
}
|
||||
|
||||
func pathWithin(path string, prefix []string) bool {
|
||||
child := pointerTokens(path)
|
||||
if len(prefix) > len(child) {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user