mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
lib/model: Add option for overwriting names on connect (fixes #2912)
This commit is contained in:
parent
2eb8a9ef56
commit
4389bb037d
@ -61,6 +61,7 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
URPostInsecurely: false,
|
URPostInsecurely: false,
|
||||||
ReleasesURL: "https://api.github.com/repos/syncthing/syncthing/releases?per_page=30",
|
ReleasesURL: "https://api.github.com/repos/syncthing/syncthing/releases?per_page=30",
|
||||||
AlwaysLocalNets: []string{},
|
AlwaysLocalNets: []string{},
|
||||||
|
OverwriteNames: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := New(device1)
|
cfg := New(device1)
|
||||||
@ -190,6 +191,7 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
URPostInsecurely: true,
|
URPostInsecurely: true,
|
||||||
ReleasesURL: "https://localhost/releases",
|
ReleasesURL: "https://localhost/releases",
|
||||||
AlwaysLocalNets: []string{},
|
AlwaysLocalNets: []string{},
|
||||||
|
OverwriteNames: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
||||||
|
@ -39,6 +39,7 @@ type OptionsConfiguration struct {
|
|||||||
MinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct" json:"minHomeDiskFreePct" default:"1"`
|
MinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct" json:"minHomeDiskFreePct" default:"1"`
|
||||||
ReleasesURL string `xml:"releasesURL" json:"releasesURL" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=30"`
|
ReleasesURL string `xml:"releasesURL" json:"releasesURL" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=30"`
|
||||||
AlwaysLocalNets []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
|
AlwaysLocalNets []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
|
||||||
|
OverwriteNames bool `xml:"overwriteNames" json:"overwriteNames" default:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (orig OptionsConfiguration) Copy() OptionsConfiguration {
|
func (orig OptionsConfiguration) Copy() OptionsConfiguration {
|
||||||
|
1
lib/config/testdata/overridenvalues.xml
vendored
1
lib/config/testdata/overridenvalues.xml
vendored
@ -34,5 +34,6 @@
|
|||||||
<urInitialDelayS>800</urInitialDelayS>
|
<urInitialDelayS>800</urInitialDelayS>
|
||||||
<urPostInsecurely>true</urPostInsecurely>
|
<urPostInsecurely>true</urPostInsecurely>
|
||||||
<releasesURL>https://localhost/releases</releasesURL>
|
<releasesURL>https://localhost/releases</releasesURL>
|
||||||
|
<overwriteNames>true</overwriteNames>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -1007,7 +1007,7 @@ func (m *Model) AddConnection(conn Connection, hello protocol.HelloMessage) {
|
|||||||
l.Infof(`Device %s client is "%s %s" named "%s"`, deviceID, hello.ClientName, hello.ClientVersion, hello.DeviceName)
|
l.Infof(`Device %s client is "%s %s" named "%s"`, deviceID, hello.ClientName, hello.ClientVersion, hello.DeviceName)
|
||||||
|
|
||||||
device, ok := m.cfg.Devices()[deviceID]
|
device, ok := m.cfg.Devices()[deviceID]
|
||||||
if ok && device.Name == "" {
|
if ok && (device.Name == "" || m.cfg.Options().OverwriteNames) {
|
||||||
device.Name = hello.DeviceName
|
device.Name = hello.DeviceName
|
||||||
m.cfg.SetDevice(device)
|
m.cfg.SetDevice(device)
|
||||||
m.cfg.Save()
|
m.cfg.Save()
|
||||||
|
@ -357,6 +357,19 @@ func TestDeviceRename(t *testing.T) {
|
|||||||
if cfgw.Devices()[device1].Name != "tester" {
|
if cfgw.Devices()[device1].Name != "tester" {
|
||||||
t.Errorf("Device name not saved in config")
|
t.Errorf("Device name not saved in config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Close(device1, protocol.ErrTimeout)
|
||||||
|
|
||||||
|
opts := cfg.Options()
|
||||||
|
opts.OverwriteNames = true
|
||||||
|
cfg.SetOptions(opts)
|
||||||
|
|
||||||
|
hello.DeviceName = "tester2"
|
||||||
|
m.AddConnection(conn, hello)
|
||||||
|
|
||||||
|
if cfg.Devices()[device1].Name != "tester2" {
|
||||||
|
t.Errorf("Device name not overwritten")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClusterConfig(t *testing.T) {
|
func TestClusterConfig(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user