Prepare collection policy transport through inheritance
This commit is contained in:
@@ -7,10 +7,13 @@ const inheritanceKey = "extends"
|
||||
// These private records keep structural evidence separate from acquired source
|
||||
// records. Later inspection can project a transfer onto individual descendants.
|
||||
type inheritanceTransfer struct {
|
||||
from Path
|
||||
to Path
|
||||
reference Path
|
||||
locations []Location
|
||||
from Path
|
||||
to Path
|
||||
reference Path
|
||||
locations []Location
|
||||
policyTemplates []collectionPolicyScope
|
||||
templatePolicies collectionPolicyScope
|
||||
projectedPolicies []projectedCollectionPolicy
|
||||
}
|
||||
|
||||
type inheritanceControl struct {
|
||||
@@ -20,22 +23,125 @@ type inheritanceControl struct {
|
||||
}
|
||||
|
||||
type inheritanceScope struct {
|
||||
root *document.Node
|
||||
origins map[string]Origin
|
||||
transfers []inheritanceTransfer
|
||||
controls []inheritanceControl
|
||||
replacements []inheritanceReplacement
|
||||
operations []inheritanceOperation
|
||||
root *document.Node
|
||||
origins map[string]Origin
|
||||
collectionPolicies collectionPolicyScope
|
||||
transfers []inheritanceTransfer
|
||||
controls []inheritanceControl
|
||||
replacements []inheritanceReplacement
|
||||
operations []inheritanceOperation
|
||||
}
|
||||
|
||||
type inheritanceOperation struct {
|
||||
control *inheritanceControl
|
||||
transfer *inheritanceTransfer
|
||||
controlOrigin Origin
|
||||
parent *document.Node
|
||||
effective *document.Node
|
||||
parentOrigins map[string]Origin
|
||||
effectiveOrigins map[string]Origin
|
||||
control *inheritanceControl
|
||||
transfer *inheritanceTransfer
|
||||
controlOrigin Origin
|
||||
parent *document.Node
|
||||
effective *document.Node
|
||||
parentOrigins map[string]Origin
|
||||
effectiveOrigins map[string]Origin
|
||||
parentPolicies []collectionPolicyScope
|
||||
templatePolicies collectionPolicyScope
|
||||
effectivePolicies []collectionPolicyScope
|
||||
}
|
||||
|
||||
func cloneInheritancePolicyTemplates(templates []collectionPolicyScope) []collectionPolicyScope {
|
||||
if templates == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]collectionPolicyScope, len(templates))
|
||||
for index, template := range templates {
|
||||
cloned[index] = cloneCollectionPolicyScopeForInheritance(template)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func cloneProjectedInheritancePolicies(policies []projectedCollectionPolicy) []projectedCollectionPolicy {
|
||||
if policies == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]projectedCollectionPolicy, len(policies))
|
||||
for index, policy := range policies {
|
||||
cloned[index] = projectedCollectionPolicy{
|
||||
path: policy.path.clone(), policy: cloneCollectionPolicyForInheritance(policy.policy),
|
||||
}
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func cloneInheritanceTransfer(transfer inheritanceTransfer) inheritanceTransfer {
|
||||
cloned := transfer
|
||||
cloned.from = transfer.from.clone()
|
||||
cloned.to = transfer.to.clone()
|
||||
cloned.reference = transfer.reference.clone()
|
||||
cloned.locations = append([]Location(nil), transfer.locations...)
|
||||
cloned.policyTemplates = cloneInheritancePolicyTemplates(transfer.policyTemplates)
|
||||
cloned.templatePolicies = cloneCollectionPolicyScopeForInheritance(transfer.templatePolicies)
|
||||
cloned.projectedPolicies = cloneProjectedInheritancePolicies(transfer.projectedPolicies)
|
||||
return cloned
|
||||
}
|
||||
|
||||
func cloneInheritanceOperations(operations []inheritanceOperation) []inheritanceOperation {
|
||||
if operations == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]inheritanceOperation, len(operations))
|
||||
for index, operation := range operations {
|
||||
cloned[index] = operation
|
||||
if operation.control != nil {
|
||||
control := *operation.control
|
||||
control.path = operation.control.path.clone()
|
||||
control.locations = append([]Location(nil), operation.control.locations...)
|
||||
cloned[index].control = &control
|
||||
}
|
||||
if operation.transfer != nil {
|
||||
transfer := cloneInheritanceTransfer(*operation.transfer)
|
||||
cloned[index].transfer = &transfer
|
||||
}
|
||||
cloned[index].parent = document.Clone(operation.parent)
|
||||
cloned[index].effective = document.Clone(operation.effective)
|
||||
cloned[index].parentOrigins = cloneOriginIndex(operation.parentOrigins)
|
||||
cloned[index].effectiveOrigins = cloneOriginIndex(operation.effectiveOrigins)
|
||||
cloned[index].parentPolicies = cloneInheritancePolicyTemplates(operation.parentPolicies)
|
||||
cloned[index].templatePolicies = cloneCollectionPolicyScopeForInheritance(operation.templatePolicies)
|
||||
cloned[index].effectivePolicies = cloneInheritancePolicyTemplates(operation.effectivePolicies)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func inheritancePolicyScopeAtPath(scope collectionPolicyScope, prefix Path) collectionPolicyScope {
|
||||
localized := collectionPolicyScope{}
|
||||
for _, entry := range scope.collections {
|
||||
if relative, inside := relativeHistoryPath(prefix, entry.destination); inside {
|
||||
localized.set(relative, cloneCollectionPolicyForInheritance(entry.policy))
|
||||
continue
|
||||
}
|
||||
relative, inside := relativeHistoryPath(entry.destination, prefix)
|
||||
if !inside || len(relative.segments) == 0 || relative.segments[0].kind != pathSegmentIndex {
|
||||
continue
|
||||
}
|
||||
record, found := entry.policy.recordPolicyAt(relative.segments[0].index)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
remainder := Path{segments: append([]pathSegment(nil), relative.segments[1:]...)}
|
||||
for _, nested := range inheritancePolicyScopeAtPath(record.scope, remainder).collections {
|
||||
localized.set(nested.destination, cloneCollectionPolicyForInheritance(nested.policy))
|
||||
}
|
||||
}
|
||||
return localized
|
||||
}
|
||||
|
||||
func projectInheritancePolicyTemplates(templates []collectionPolicyScope, prefix Path) []projectedCollectionPolicy {
|
||||
var projected []projectedCollectionPolicy
|
||||
for _, template := range templates {
|
||||
for _, policy := range projectCollectionPolicyScope(template, prefix) {
|
||||
projected = append(projected, projectedCollectionPolicy{
|
||||
path: policy.path.clone(), policy: cloneCollectionPolicyForInheritance(policy.policy),
|
||||
})
|
||||
}
|
||||
}
|
||||
return projected
|
||||
}
|
||||
|
||||
// A replacement retains the displaced source/derivation record while the
|
||||
|
||||
Reference in New Issue
Block a user