From ad4e3769eb673600aa484e7b1eaa0e1645d0bb2d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 13 Jul 2024 04:24:55 -0400 Subject: [PATCH] dyndns2: Invert condition to improve readability --- ddclient.in | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/ddclient.in b/ddclient.in index 56897a2..c981b37 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4092,30 +4092,32 @@ sub nic_dyndns2_update { $config{$h}{'status-ipv4'} = $status if $ipv4; $config{$h}{'status-ipv6'} = $status if $ipv6; } - if ($status eq 'good') { - for my $h (@hosts) { - $config{$h}{'ipv4'} = $ipv4 if $ipv4; - $config{$h}{'ipv6'} = $ipv6 if $ipv6; - $config{$h}{'mtime'} = $now; + if ($status ne 'good') { + if (exists($errors{$status})) { + failed("updating %s: %s: %s", $hosts, $status, $errors{$status}); + } elsif ($status =~ qr/w(\d+)(.)/) { + my ($wait, $units) = ($1, lc $2); + my ($sec, $scale) = ($wait, 1); + ($scale, $units) = (1, 'seconds') if $units eq 's'; + ($scale, $units) = (60, 'minutes') if $units eq 'm'; + ($scale, $units) = (60*60, 'hours') if $units eq 'h'; + $sec = $wait * $scale; + for my $h (@hosts) { + $config{$h}{'wtime'} = $now + $sec; + } + warning("updating %s: %s: wait %s %s before further updates", $hosts, $status, $wait, $units); + } else { + failed("updating %s: unexpected status (%s)", $hosts, $line); } - success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4; - success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6; - } elsif (exists $errors{$status}) { - failed("updating %s: %s: %s", $hosts, $status, $errors{$status}); - } elsif ($status =~ /w(\d+)(.)/) { - my ($wait, $units) = ($1, lc $2); - my ($sec, $scale) = ($wait, 1); - ($scale, $units) = (1, 'seconds') if $units eq 's'; - ($scale, $units) = (60, 'minutes') if $units eq 'm'; - ($scale, $units) = (60*60, 'hours') if $units eq 'h'; - $sec = $wait * $scale; - for my $h (@hosts) { - $config{$h}{'wtime'} = $now + $sec; - } - warning("updating %s: %s: wait %s %s before further updates", $hosts, $status, $wait, $units); - } else { - failed("updating %s: unexpected status (%s)", $hosts, $line); + next; } + for my $h (@hosts) { + $config{$h}{'ipv4'} = $ipv4 if $ipv4; + $config{$h}{'ipv6'} = $ipv6 if $ipv6; + $config{$h}{'mtime'} = $now; + } + success("updating %s: %s: IPv4 address set to %s", $hosts, $status, $ipv4) if $ipv4; + success("updating %s: %s: IPv6 address set to %s", $hosts, $status, $ipv6) if $ipv6; } }