Skip to content

Commit

Permalink
removed multiple warnings when device name not found
Browse files Browse the repository at this point in the history
  • Loading branch information
wsw70 committed Jan 17, 2023
1 parent e5a179a commit 10ae9f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module syncthing-map
go 1.19

require (
github.com/deckarep/golang-set/v2 v2.1.0
github.com/go-chi/chi/v5 v5.0.8
github.com/rs/zerolog v1.28.0
github.com/urfave/cli/v2 v2.23.7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down
11 changes: 5 additions & 6 deletions readConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"encoding/xml"
"fmt"
"os"
"strings"

mapset "github.com/deckarep/golang-set/v2"
)

// readConfigXML takes the hostname and config file and dumps a data-cli.json representation for further use
Expand All @@ -23,6 +24,7 @@ func readConfigXml(hostname string, configFile string, dataFilename string) {
log.Fatal().Msgf("cannot unmarshall config.xml: %v", err)
}
// update the devices names in folders
devicesFound := mapset.NewSet[string]() // unique set of devices found in the folders
for _, folder := range config.Folder {
for i, device := range folder.Device {
// find the appropraite device name
Expand All @@ -35,15 +37,12 @@ func readConfigXml(hostname string, configFile string, dataFilename string) {
if hostname == knownDevice.Name {
localDeviceId = knownDevice.ID
}
// try to see if the names match without case
if strings.EqualFold(hostname, knownDevice.Name) {
log.Warn().Msgf("provided device name %s matches %s caseless", hostname, knownDevice.Name)
}
devicesFound.Add(knownDevice.Name)
}
}
}
if localDeviceId == "" {
log.Fatal().Msgf("could not match the provided device name %s with known devices in the config file. Check for a warning above if this is not just a matter of case", hostname)
log.Fatal().Msgf("could not match the provided device name %s with known devices in the config file. Found device names: %v", hostname, devicesFound)
}

writeConfigToFile(fmt.Sprintf("%s %s", hostname, localDeviceId), config, dataFilename)
Expand Down

0 comments on commit 10ae9f8

Please sign in to comment.