mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Save config on device rename (fixes #957)
This commit is contained in:
parent
9b78582475
commit
39a3b8922d
@ -527,12 +527,15 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
|
||||
l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)
|
||||
|
||||
var changed bool
|
||||
|
||||
if name := cm.GetOption("name"); name != "" {
|
||||
l.Infof("Device %s name is %q", deviceID, name)
|
||||
device, ok := m.cfg.Devices()[deviceID]
|
||||
if ok && device.Name == "" {
|
||||
device.Name = name
|
||||
m.cfg.SetDevice(device)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -540,7 +543,6 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
// This device is an introducer. Go through the announced lists of folders
|
||||
// and devices and add what we are missing.
|
||||
|
||||
var changed bool
|
||||
for _, folder := range cm.Folders {
|
||||
// If we don't have this folder yet, skip it. Ideally, we'd
|
||||
// offer up something in the GUI to create the folder, but for the
|
||||
@ -599,12 +601,12 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
m.cfg.Save()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close removes the peer from the model and closes the underlying connection if possible.
|
||||
// Implements the protocol.Model interface.
|
||||
|
@ -258,6 +258,8 @@ func TestDeviceRename(t *testing.T) {
|
||||
ClientVersion: "v0.9.4",
|
||||
}
|
||||
|
||||
defer os.Remove("tmpconfig.xml")
|
||||
|
||||
cfg := config.New(device1)
|
||||
cfg.Devices = []config.DeviceConfiguration{
|
||||
{
|
||||
@ -266,7 +268,7 @@ func TestDeviceRename(t *testing.T) {
|
||||
}
|
||||
|
||||
db, _ := leveldb.Open(storage.NewMemStorage(), nil)
|
||||
m := NewModel(config.Wrap("/tmp/test", cfg), "device", "syncthing", "dev", db)
|
||||
m := NewModel(config.Wrap("tmpconfig.xml", cfg), "device", "syncthing", "dev", db)
|
||||
if cfg.Devices[0].Name != "" {
|
||||
t.Errorf("Device already has a name")
|
||||
}
|
||||
@ -292,6 +294,15 @@ func TestDeviceRename(t *testing.T) {
|
||||
if cfg.Devices[0].Name != "tester" {
|
||||
t.Errorf("Device name got overwritten")
|
||||
}
|
||||
|
||||
cfgw, err := config.Load("tmpconfig.xml", protocol.LocalDeviceID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if cfgw.Devices()[device1].Name != "tester" {
|
||||
t.Errorf("Device name not saved in config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterConfig(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user