mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Make duplicate ID:s temporarily unique (fixes #153)
This commit is contained in:
parent
dc2f83e522
commit
76f82cbd1f
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -178,6 +179,7 @@ func readConfigXML(rd io.Reader, myID string) (Configuration, error) {
|
|||||||
|
|
||||||
// Check for missing, bad or duplicate repository ID:s
|
// Check for missing, bad or duplicate repository ID:s
|
||||||
var seenRepos = map[string]*RepositoryConfiguration{}
|
var seenRepos = map[string]*RepositoryConfiguration{}
|
||||||
|
var uniqueCounter int
|
||||||
for i := range cfg.Repositories {
|
for i := range cfg.Repositories {
|
||||||
repo := &cfg.Repositories[i]
|
repo := &cfg.Repositories[i]
|
||||||
|
|
||||||
@ -191,9 +193,16 @@ func readConfigXML(rd io.Reader, myID string) (Configuration, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if seen, ok := seenRepos[repo.ID]; ok {
|
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)
|
warnf("Multiple repositories with ID %q; disabling", repo.ID)
|
||||||
|
|
||||||
|
seen.Invalid = "duplicate repository ID"
|
||||||
|
if seen.ID == repo.ID {
|
||||||
|
uniqueCounter++
|
||||||
|
seen.ID = fmt.Sprintf("%s~%d", repo.ID, uniqueCounter)
|
||||||
|
}
|
||||||
|
repo.Invalid = "duplicate repository ID"
|
||||||
|
uniqueCounter++
|
||||||
|
repo.ID = fmt.Sprintf("%s~%d", repo.ID, uniqueCounter)
|
||||||
} else {
|
} else {
|
||||||
seenRepos[repo.ID] = repo
|
seenRepos[repo.ID] = repo
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user