Skip to content

Commit

Permalink
restore from broken configuration, now mainly from unknown udev link …
Browse files Browse the repository at this point in the history
…(bsc#931291)
  • Loading branch information
jreidinger committed Oct 6, 2016
1 parent eef9f97 commit 47105a5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/lib/bootloader/config_dialog.rb
Expand Up @@ -52,6 +52,19 @@ def run
next_button: Yast::Label.OKButton,
skip_store_for: [:redraw]
)
rescue ::Bootloader::BrokenConfiguration => e
ret = Yast::Report.AnyQuestion(_("Broken Configuration"),
_("Bootloader configuration is broken (%s). Propose configuration from scratch?") %
e.reason,
_("Propose"),
_("Quit"),
:yes) # focus proposing new one
return :abort unless ret

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose

retry
end
end
end
15 changes: 15 additions & 0 deletions src/lib/bootloader/exceptions.rb
@@ -1,3 +1,5 @@
require "yast"

module Bootloader
# Represents error when during read it found bootloader name that is not supported.
class UnsupportedBootloader < RuntimeError
Expand All @@ -7,4 +9,17 @@ def initialize(bootloader_name)
@bootloader_name = bootloader_name
end
end

class BrokenConfiguration < RuntimeError
include Yast::I18n
attr_reader :reason

def initialize(msg)
@reason = msg
textdomain "bootloader"

super _("Found problem during reading bootloader configuration files. " \
"Please open bootloader module and fix it. Details: %s") % msg
end
end
end
15 changes: 13 additions & 2 deletions src/lib/bootloader/udev_mapping.rb
@@ -1,6 +1,8 @@
require "yast"
require "singleton"

require "bootloader/exceptions"

Yast.import "Storage"
Yast.import "Mode"
Yast.import "Arch"
Expand All @@ -10,6 +12,7 @@ module Bootloader
class UdevMapping
include Singleton
include Yast::Logger
include Yast::I18n

# make more comfortable to work with singleton
class << self
Expand All @@ -24,13 +27,21 @@ class << self
# @raise when device have udev format but do not exists
# @return [String,nil] kernel device or nil when running AutoYaST configuration.
def to_kernel_device(dev)
textdomain "bootloader"
log.info "call to_kernel_device for #{dev}"
raise "invalid device nil" unless dev

# for non-udev devices try to see specific raid names (bnc#944041)
if dev =~ /^\/dev\/disk\/by-/
# in mode config if not found, then return itself
all_devices[dev] or Yast::Mode.config ? dev : raise("Unknown udev device #{dev}")
# TRANSLATORS: error message, %s stands for problematic device.
if all_devices[dev]
return all_devices[dev]
else
# in mode config if not found, then return itself
return dev if Yast::Mode.config

raise(Bootloader::BrokenConfiguration, _("Unknown udev device '%s'") % dev)
end
else
param = Yast::ArgRef.new({})
result = Yast::Storage.GetContVolInfo(dev, param)
Expand Down
11 changes: 11 additions & 0 deletions src/modules/Bootloader.rb
Expand Up @@ -163,6 +163,17 @@ def Read
:yes) # focus proposing new one
return false unless ret

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose
rescue ::Bootloader::BrokenConfiguration => e
ret = Yast::Report.AnyQuestion(_("Broken Configuration"),
_("Bootloader configuration is broken (%s). Propose configuration from scratch?") %
e.reason,
_("Propose"),
_("Quit"),
:yes) # focus proposing new one
return false unless ret

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose
end
Expand Down

0 comments on commit 47105a5

Please sign in to comment.