Skip to content

Commit

Permalink
adapted suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Mar 6, 2020
1 parent 603c746 commit f52bfa0
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/clients/ntp-client_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ def Write(params)
ntp_server = UI.QueryWidget(Id(:ntp_address), :Value)
end

return :invalid_hostname unless ValidateSingleServer(ntp_server)
if !ntp_server.empty? && !ValidateSingleServer(ntp_server)
return :invalid_hostname
end

add_or_install_required_package unless params["write_only"]

Expand All @@ -391,13 +393,20 @@ def Write(params)
# Only if network is running try to synchronize
# the ntp server.
if NetworkService.isNetworkRunning && !Service.Active(NtpClient.service_name)
if !select_ntp_server && ntp_server.empty?
# Trying first server in the list
ntp_server = NtpClient.GetUsedNtpServers.first unless NtpClient.GetUsedNtpServers.nil?
ntp_servers = [ntp_server]
if !select_ntp_server
# Taking also the rest of the ntp servers, configured in the ntp client module.
ntp_servers += NtpClient.GetUsedNtpServers unless NtpClient.GetUsedNtpServers.nil?
end
ntp_servers.delete("")
ntp_servers.uniq
exit_code = 0
ntp_servers.each do |server|
Popup.ShowFeedback("", _("Synchronizing with NTP server...") + server)
exit_code = NtpClient.sync_once(server)
Popup.ClearFeedback
break if exit_code.zero?
end
Popup.ShowFeedback("", _("Synchronizing with NTP server..."))
exit_code = NtpClient.sync_once(ntp_server)
Popup.ClearFeedback

return :ntpdate_failed unless exit_code.zero?
end
Expand Down Expand Up @@ -461,11 +470,11 @@ def ui_try_save

rv = Write(argmap)

server = if select_ntp_server
Convert.to_string(UI.QueryWidget(Id(:ntp_address), :Value))
else
NtpClient.GetUsedNtpServers.first
end
# The user has not had the possibility to change the ntp server.
# So we are done here.
return true unless select_ntp_server

server = Convert.to_string(UI.QueryWidget(Id(:ntp_address), :Value))
Builtins.y2milestone("ui_try_save argmap %1", argmap)
if rv == :invalid_hostname
handle_invalid_hostname(server)
Expand Down Expand Up @@ -548,7 +557,7 @@ def fallback_ntp_items

# Checking if the user can select one ntp server from the list
# of proposed servers.
# It does not make sense if there are more than one ntp server has been
# It does not make sense if there are more than one ntp server
# defined.
#
# @return [Boolean] true if the user should select a server
Expand Down

0 comments on commit f52bfa0

Please sign in to comment.