dependency: don't recurse infinitely.
If we have a dependency cycle ensure that infinite recursion does not result by storing state in a stack which we push/pop from for each level of recursion and verify that we haven’t been through this dependency already. Closes Homebrew/homebrew#47933. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
42681b51f8
commit
20106e4268
@ -71,25 +71,31 @@ class Dependency
|
||||
# The default filter, which is applied when a block is not given, omits
|
||||
# optionals and recommendeds based on what the dependent has asked for.
|
||||
def expand(dependent, deps = dependent.deps, &block)
|
||||
# Keep track dependencies to avoid infinite cyclic dependency recursion.
|
||||
@expand_stack ||= []
|
||||
@expand_stack.push dependent.name
|
||||
|
||||
expanded_deps = []
|
||||
|
||||
deps.each do |dep|
|
||||
# FIXME: don't hide cyclic dependencies
|
||||
next if dependent.name == dep.name
|
||||
|
||||
case action(dependent, dep, &block)
|
||||
when :prune
|
||||
next
|
||||
when :skip
|
||||
next if @expand_stack.include? dep.name
|
||||
expanded_deps.concat(expand(dep.to_formula, &block))
|
||||
when :keep_but_prune_recursive_deps
|
||||
expanded_deps << dep
|
||||
else
|
||||
next if @expand_stack.include? dep.name
|
||||
expanded_deps.concat(expand(dep.to_formula, &block))
|
||||
expanded_deps << dep
|
||||
end
|
||||
end
|
||||
|
||||
@expand_stack.pop
|
||||
merge_repeats(expanded_deps)
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user