Skip to content

Commit

Permalink
Do not crash when sorting the modules descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 7, 2021
1 parent 3cf0c1f commit a6204e4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib/autoinstall/entries/description_sorter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Y2Autoinstallation
module Entries
# Worker class for sorting description according their dependencies
class DescriptionSorter
include Yast::Logger

def initialize(descriptions)
@descriptions = descriptions
@descriptions_map = Hash[descriptions.map { |d| [d.module_name, d] }]
Expand All @@ -31,10 +33,21 @@ def initialize(descriptions)
# @return [Array<Description>] sorted module names. It should be written
# from first to the last.
def sort
each_node = ->(&b) { @descriptions_map.each_key(&b) }
each_child = ->(n, &b) { @descriptions_map[n].required_modules.each(&b) }
each_node = lambda do |&b|
@descriptions_map.each_key(&b)
end

each_child = lambda do |n, &b|
desc = @descriptions_map[n]
if desc
desc.required_modules.each(&b)
else
log.error "Unknown module description '#{n}'"
end
end

TSort.tsort(each_node, each_child).map { |mn| @descriptions_map[mn] }
log.info "Sorting module descriptions: #{@descriptions.inspect}"
TSort.tsort(each_node, each_child).map { |mn| @descriptions_map[mn] }.compact
end
end
end
Expand Down

0 comments on commit a6204e4

Please sign in to comment.