Allow node IDs with spaces/dashes in config. Use dashes in GUI. (ref #230)

This commit is contained in:
Jakob Borg
2014-05-18 12:05:17 +02:00
parent 729b0143e1
commit bbefcef53b
5 changed files with 74 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"code.google.com/p/go.crypto/bcrypt"
"github.com/calmh/syncthing/logger"
@@ -181,6 +182,14 @@ func Load(rd io.Reader, myID string) (Configuration, error) {
cfg.Repositories = []RepositoryConfiguration{}
}
// Sanitize node IDs
for i := range cfg.Nodes {
node := &cfg.Nodes[i]
// Strip spaces and dashes
node.NodeID = strings.Replace(node.NodeID, "-", "", -1)
node.NodeID = strings.Replace(node.NodeID, " ", "", -1)
}
// Check for missing, bad or duplicate repository ID:s
var seenRepos = map[string]*RepositoryConfiguration{}
var uniqueCounter int
@@ -196,6 +205,13 @@ func Load(rd io.Reader, myID string) (Configuration, error) {
repo.ID = "default"
}
for i := range repo.Nodes {
node := &repo.Nodes[i]
// Strip spaces and dashes
node.NodeID = strings.Replace(node.NodeID, "-", "", -1)
node.NodeID = strings.Replace(node.NodeID, " ", "", -1)
}
if seen, ok := seenRepos[repo.ID]; ok {
l.Warnf("Multiple repositories with ID %q; disabling", repo.ID)