Skip to content

Commit

Permalink
Do not catch only when renaming first time, but also in case of a res…
Browse files Browse the repository at this point in the history
…tore through rename
  • Loading branch information
teclator committed Feb 12, 2019
1 parent 40d4aeb commit 8dd80b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
25 changes: 13 additions & 12 deletions src/include/network/lan/address.rb
Expand Up @@ -1211,6 +1211,8 @@ def wireless_tab
def AddressDialog
initialize_address_settings

cached_name = LanItems.current_name

wd = Convert.convert(
Builtins.union(@widget_descr, @widget_descr_local),
from: "map",
Expand Down Expand Up @@ -1391,15 +1393,14 @@ def AddressDialog
# proceed with WLAN settings if appropriate, #42420
ret = :wire if ret == :next && LanItems.type == "wlan"

if LanItems.current_renamed?
if cached_name != LanItems.current_name
Routing.SetDevices(LanItems.current_device_names)
update_routes! if update_routes?
update_routes!(cached_name) if update_routes?(cached_name)
end

deep_copy(ret)
end


private

# Initializes the Address Dialog @settings with the corresponding LanItems values
Expand Down Expand Up @@ -1445,25 +1446,25 @@ def initialize_address_settings
# update the interface name in the related routes or not.
#
# return [Boolean] whether the routes have to be updated or not
def update_routes?
return false unless Routing.device_routes?(LanItems.GetCurrentName)
def update_routes?(previous_name)
return false unless Routing.device_routes?(previous_name)

Popup.YesNoHeadline(
Label.WarningMsg,
# TRANSLATORS: Ask for fixing a possible conflict after renaming
# an interface, %1 is the previous interface name %2 is the current one
format(_("The interface %s has been renamed to %s. There are some " \
"routes that still use the previous name.\n\n" \
"Would you like to update them now?\n"),
"'#{LanItems.current_name}'",
"'#{LanItems.GetCurrentName}'")
format(_("The interface %s has been renamed to %s. There are \n" \
"some routes that still use the previous name.\n\n" \
"Would you like to update them now?\n"),
"'#{previous_name}'",
"'#{LanItems.current_name}'")
)
end

# It modifies the interface name with the new one of all the routes
# that belongs to the current renamed {LanItem}
def update_routes!
Routing.device_routes(LanItems.GetCurrentName).each do |route|
def update_routes!(previous_name)
Routing.device_routes(previous_name).each do |route|
route["device"] = LanItems.current_name
end
end
Expand Down
5 changes: 4 additions & 1 deletion src/modules/LanItems.rb
Expand Up @@ -2184,7 +2184,10 @@ def Commit
# @return [true] so that this can be used for the :abort callback
def Rollback
log.info "rollback item #{@current}"
if getCurrentItem.fetch("hwinfo", {}).empty?
# Do not delete elements that are :edited but does not contain hwinfo
# yet (Add a virtual device and then edit it canceling the process during the
# edition)
if LanItems.operation == :add && getCurrentItem.fetch("hwinfo", {}).empty?
LanItems.Items.delete(@current)
elsif IsCurrentConfigured()
if !getNetworkInterfaces.include?(getCurrentItem["ifcfg"])
Expand Down
1 change: 0 additions & 1 deletion src/modules/Routing.rb
Expand Up @@ -147,7 +147,6 @@ def ReadFromGateway(gw)
true
end


def device_routes(device)
@Routes.select { |r| r["device"] == device }
end
Expand Down

0 comments on commit 8dd80b6

Please sign in to comment.