|
|
@ -6,6 +6,7 @@ package portlist
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -76,6 +77,7 @@ func GetList(prev List) (List, error) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("listPorts: %s", err)
|
|
|
|
return nil, fmt.Errorf("listPorts: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pl = sortAndDedup(pl)
|
|
|
|
if pl.sameInodes(prev) {
|
|
|
|
if pl.sameInodes(prev) {
|
|
|
|
// Nothing changed, skip inode lookup
|
|
|
|
// Nothing changed, skip inode lookup
|
|
|
|
return prev, nil
|
|
|
|
return prev, nil
|
|
|
@ -86,3 +88,22 @@ func GetList(prev List) (List, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pl, nil
|
|
|
|
return pl, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sortAndDedup sorts ps in place (by Port.lessThan) and then returns
|
|
|
|
|
|
|
|
// a subset of it with duplicate (Proto, Port) removed.
|
|
|
|
|
|
|
|
func sortAndDedup(ps List) List {
|
|
|
|
|
|
|
|
sort.Slice(ps, func(i, j int) bool {
|
|
|
|
|
|
|
|
return (&ps[i]).lessThan(&ps[j])
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
out := ps[:0]
|
|
|
|
|
|
|
|
var last Port
|
|
|
|
|
|
|
|
for _, p := range ps {
|
|
|
|
|
|
|
|
protoPort := Port{Proto: p.Proto, Port: p.Port}
|
|
|
|
|
|
|
|
if last == protoPort {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, p)
|
|
|
|
|
|
|
|
last = protoPort
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
}
|
|
|
|