mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-05-28 04:36:05 -04:00
Validate path starts with source and ends with destination
This commit is contained in:
parent
870c5f6808
commit
1d4c57222f
1 changed files with 16 additions and 1 deletions
|
|
@ -56,12 +56,23 @@ module VagrantPlugins
|
|||
|
||||
# Apply topological sort to the graph so we have
|
||||
# a proper for execution
|
||||
Array.new.tap do |path|
|
||||
result = Array.new.tap do |path|
|
||||
t = graph.topsort_iterator
|
||||
until t.at_end?
|
||||
path << t.forward
|
||||
end
|
||||
end
|
||||
|
||||
if result.first != src
|
||||
raise NoPathError,
|
||||
"Initial vertex is not source #{src} != #{result.first}"
|
||||
end
|
||||
|
||||
if result.last != dst
|
||||
raise NoPathError,
|
||||
"Final vertex is not destination #{dst} != #{result.last}"
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -70,6 +81,10 @@ module VagrantPlugins
|
|||
def generate_path(src, dst)
|
||||
begin
|
||||
path = graph.shortest_path(src, dst)
|
||||
o = Array(path).map { |v|
|
||||
"#{v} ->"
|
||||
}.join("\n")
|
||||
logger.debug("path generation #{src} -> #{dst}\n#{o}")
|
||||
if path.nil?
|
||||
raise NoPathError,
|
||||
"Path generation failed to reach destination (#{dst&.type&.inspect})"
|
||||
|
|
|
|||
Loading…
Reference in a new issue