Skip to content

Commit 9b35575

Browse files
committed
Remove none ipv4 entry from /etc/hosts
1 parent a495f52 commit 9b35575

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

components/workspacekit/cmd/rings.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,22 +695,27 @@ func makeHostnameLocal(ring2root string) error {
695695
if err != nil {
696696
return err
697697
}
698-
b, err := ioutil.ReadFile(path)
698+
b, err := os.ReadFile(path)
699699
if err != nil {
700700
return err
701701
}
702702
bStr := string(b)
703703
lines := strings.Split(bStr, "\n")
704-
for i, line := range lines {
704+
newLines := []string{}
705+
for _, line := range lines {
705706
fields := strings.Fields(line)
706707
if len(fields) != 2 {
708+
newLines = append(newLines, line)
709+
continue
710+
}
711+
if len(net.ParseIP(fields[0])) != net.IPv4len {
707712
continue
708713
}
709714
if fields[1] == hostname {
710-
lines[i] = "127.0.0.1 " + hostname
715+
newLines = append(newLines, "127.0.0.1 "+hostname)
711716
}
712717
}
713-
return ioutil.WriteFile(path, []byte(strings.Join(lines, "\n")), stat.Mode())
718+
return os.WriteFile(path, []byte(strings.Join(newLines, "\n")), stat.Mode())
714719
}
715720

716721
func receiveSeccmpFd(conn *net.UnixConn) (libseccomp.ScmpFd, error) {

0 commit comments

Comments
 (0)