mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 00:32:09 -04:00
internal/dag: adapt Validate to not check for Root
The implementation of the DAG as extracted from Terraform relied on a Root vertex being injected into the graph as the last node to visit. This is used as a sanity check for Terraform, but doesn't apply to our use-case for now, as we are always executing everything and have no need for this root node. Instead, we change how Validate operates so it does not error in case there is no valid root node for the graph, but enables us calling it to check for self-referencing edges, and circular dependencies.
This commit is contained in:
parent
cd74430e0c
commit
09774aaeb8
2 changed files with 5 additions and 6 deletions
|
|
@ -420,6 +420,10 @@ func (cfg *PackerConfig) buildPrereqsDAG() (*dag.AcyclicGraph, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := retGraph.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &retGraph, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,13 +127,8 @@ func (g *AcyclicGraph) TransitiveReduction() {
|
|||
}
|
||||
}
|
||||
|
||||
// Validate validates the DAG. A DAG is valid if it has a single root
|
||||
// with no cycles.
|
||||
// Validate validates the DAG. A DAG is valid if it has no cycles or self-referencing vertex.
|
||||
func (g *AcyclicGraph) Validate() error {
|
||||
if _, err := g.Root(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Look for cycles of more than 1 component
|
||||
var err error
|
||||
cycles := g.Cycles()
|
||||
|
|
|
|||
Loading…
Reference in a new issue