diff options
author | Jakob Borg <jakob@nym.se> | 2014-04-27 21:53:27 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-04-27 21:53:27 +0200 |
commit | dcd7d278aabdffd017f10fea5e68efe241e4e64b (patch) | |
tree | fb94cb36aae660269db35d6e0004b741d00c41b5 /cmd | |
parent | 89f5f3bf9a4688c1c48a61e08b9073ae06eff99d (diff) |
Handle and indicate duplicate repo ID:s (fixes #153)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/syncthing/config.go | 19 | ||||
-rw-r--r-- | cmd/syncthing/gui.go | 7 | ||||
-rw-r--r-- | cmd/syncthing/main.go | 11 |
3 files changed, 30 insertions, 7 deletions
diff --git a/cmd/syncthing/config.go b/cmd/syncthing/config.go index 8373adf656..a5a089835a 100644 --- a/cmd/syncthing/config.go +++ b/cmd/syncthing/config.go @@ -25,6 +25,7 @@ type RepositoryConfiguration struct { Directory string `xml:"directory,attr"` Nodes []NodeConfiguration `xml:"node"` ReadOnly bool `xml:"ro,attr"` + Invalid string `xml:"-"` // Set at runtime when there is an error, not saved nodeIDs []string } @@ -171,17 +172,21 @@ func readConfigXML(rd io.Reader, myID string) (Configuration, error) { cfg.Options.ListenAddress = uniqueStrings(cfg.Options.ListenAddress) // Check for missing or duplicate repository ID:s - var seenRepos = map[string]bool{} + var seenRepos = map[string]*RepositoryConfiguration{} for i := range cfg.Repositories { - if cfg.Repositories[i].ID == "" { - cfg.Repositories[i].ID = "default" + repo := &cfg.Repositories[i] + + if repo.ID == "" { + repo.ID = "default" } - id := cfg.Repositories[i].ID - if seenRepos[id] { - panic("duplicate repository ID " + id) + if seen, ok := seenRepos[repo.ID]; ok { + seen.Invalid = "duplicate repository ID" + repo.Invalid = "duplicate repository ID" + warnf("Multiple repositories with ID %q; disabling", repo.ID) + } else { + seenRepos[repo.ID] = repo } - seenRepos[id] = true } // Upgrade to v2 configuration if appropriate diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 0119e46bc3..8033ff5c84 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -84,6 +84,13 @@ func restGetModel(m *Model, w http.ResponseWriter, r *http.Request) { var repo = qs.Get("repo") var res = make(map[string]interface{}) + for _, cr := range cfg.Repositories { + if cr.ID == repo { + res["invalid"] = cr.Invalid + break + } + } + globalFiles, globalDeleted, globalBytes := m.GlobalSize(repo) res["globalFiles"], res["globalDeleted"], res["globalBytes"] = globalFiles, globalDeleted, globalBytes diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index d84b626a9a..698e68b5fa 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -222,6 +222,9 @@ func main() { m := NewModel(cfg.Options.MaxChangeKbps * 1000) for _, repo := range cfg.Repositories { + if repo.Invalid != "" { + continue + } dir := expandTilde(repo.Directory) m.AddRepo(repo.ID, dir, repo.Nodes) } @@ -260,6 +263,10 @@ func main() { m.LoadIndexes(confDir) for _, repo := range cfg.Repositories { + if repo.Invalid != "" { + continue + } + dir := expandTilde(repo.Directory) // Safety check. If the cached index contains files but the repository @@ -295,6 +302,10 @@ func main() { go listenConnect(myID, m, tlsCfg) for _, repo := range cfg.Repositories { + if repo.Invalid != "" { + continue + } + // Routine to pull blocks from other nodes to synchronize the local // repository. Does not run when we are in read only (publish only) mode. if repo.ReadOnly { |