* hasStaticIP: use properly named boolean variable

This commit is contained in:
Simon Zolin 2019-04-05 12:47:26 +03:00
parent 6bf57ae84e
commit fa5ff053b7
1 changed files with 9 additions and 7 deletions

16
dhcp.go
View File

@ -214,14 +214,14 @@ func hasStaticIP(ifaceName string) (bool, error) {
} }
lines := strings.Split(string(body), "\n") lines := strings.Split(string(body), "\n")
nameLine := fmt.Sprintf("interface %s", ifaceName) nameLine := fmt.Sprintf("interface %s", ifaceName)
state := 0 withinInterfaceCtx := false
for _, line := range lines { for _, line := range lines {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if state == 1 && len(line) == 0 { if withinInterfaceCtx && len(line) == 0 {
// an empty line resets our state // an empty line resets our state
state = 0 withinInterfaceCtx = false
} }
if len(line) == 0 || line[0] == '#' { if len(line) == 0 || line[0] == '#' {
@ -229,14 +229,16 @@ func hasStaticIP(ifaceName string) (bool, error) {
} }
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if state == 0 { if !withinInterfaceCtx {
if line == nameLine { if line == nameLine {
state = 1 // we found our interface
withinInterfaceCtx = true
} }
} else if state == 1 { } else {
if strings.HasPrefix(line, "interface ") { if strings.HasPrefix(line, "interface ") {
state = 0 // we found another interface - reset our state
withinInterfaceCtx = false
continue continue
} }
if strings.HasPrefix(line, "static ip_address=") { if strings.HasPrefix(line, "static ip_address=") {