Validate path starts with source and ends with destination

This commit is contained in:
Chris Roberts 2021-10-29 09:04:55 -07:00 committed by Paul Hinze
parent 870c5f6808
commit 1d4c57222f
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -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})"