Skip to content

Commit

Permalink
fixes from mvidner review
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jul 13, 2016
1 parent 22e98be commit 49fbfcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -40,7 +40,7 @@ Requires: yast2-core >= 2.18.7
Requires: yast2-packager >= 2.17.24
Requires: yast2-pkg-bindings >= 2.17.25
Requires: yast2-storage >= 2.18.18
# GRUB_DEFAULT attribute
# GrubCfg with boot_entries that filter out unbootable entries
Requires: rubygem(%rb_default_ruby_abi:cfa_grub2) >= 0.5.1
# lenses are needed as cfa_grub2 depends only on augeas bindings, but also
# lenses are needed here
Expand Down
10 changes: 8 additions & 2 deletions src/lib/bootloader/sections.rb
Expand Up @@ -23,7 +23,7 @@ def default

return @default = "" if Yast::Stage.initial

default_path = read_default
default_path = read_default_path

@default = default_path ? path_to_title(default_path) : all.first
end
Expand All @@ -48,7 +48,9 @@ def write

private

def read_default
# @return [String, nil] return default boot path as string or nil if not set or something goes wrong
# @note shows error popup if calling grub2-editenv failed
def read_default_path
# Execute.on_target can return nil if call failed. It shows users error popup, but bootloader
# can continue with empty default section
saved = Yast::Execute.on_target("/usr/bin/grub2-editenv", "list", stdout: :capture) || ""
Expand All @@ -57,12 +59,16 @@ def read_default
saved_line ? saved_line[/saved_entry=(.*)$/, 1] : nil
end

# @return [String] convert grub boot path to title that can be displayed. If
# entry not found, then return argument
def path_to_title(path)
entry = @data.find { |e| e[:path] == path }

entry ? entry[:title] : path
end

# @return [String] convert displayable title to grub boot path. If
# entry not found, then return argument
def title_to_path(title)
entry = @data.find { |e| e[:title] == title }

Expand Down

0 comments on commit 49fbfcb

Please sign in to comment.