Merge pull request #654 from gravitl/bugfix_v0.10.0_get_system_networks

prevent fatal stop of mq daemon when netclient config dir contains un…
This commit is contained in:
dcarns 2022-01-31 09:16:16 -05:00 committed by GitHub
commit d480e98eb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
@ -449,18 +450,19 @@ func PrintLog(message string, loglevel int) {
// GetSystemNetworks - get networks locally
func GetSystemNetworks() ([]string, error) {
var networks []string
files, err := os.ReadDir(GetNetclientPathSpecific())
files, err := filepath.Glob(GetNetclientPathSpecific() + "netconfig-*")
if err != nil {
return networks, err
return nil, err
}
for _, f := range files {
if strings.Contains(f.Name(), "netconfig-") && !strings.Contains(f.Name(), "backup") {
networkname := stringAfter(f.Name(), "netconfig-")
networks = append(networks, networkname)
i := 0
for _, file := range files {
//don't want files such as *.bak, *.swp
if filepath.Ext(file) == "" {
files[i] = filepath.Base(file)
i++
}
}
return networks, err
return files[:i], nil
}
func stringAfter(original string, substring string) string {