mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-11 02:36:17 +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)
|
l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)
|
||||||
|
|
||||||
|
var changed bool
|
||||||
|
|
||||||
if name := cm.GetOption("name"); name != "" {
|
if name := cm.GetOption("name"); name != "" {
|
||||||
l.Infof("Device %s name is %q", deviceID, name)
|
l.Infof("Device %s name is %q", deviceID, name)
|
||||||
device, ok := m.cfg.Devices()[deviceID]
|
device, ok := m.cfg.Devices()[deviceID]
|
||||||
if ok && device.Name == "" {
|
if ok && device.Name == "" {
|
||||||
device.Name = name
|
device.Name = name
|
||||||
m.cfg.SetDevice(device)
|
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
|
// This device is an introducer. Go through the announced lists of folders
|
||||||
// and devices and add what we are missing.
|
// and devices and add what we are missing.
|
||||||
|
|
||||||
var changed bool
|
|
||||||
for _, folder := range cm.Folders {
|
for _, folder := range cm.Folders {
|
||||||
// If we don't have this folder yet, skip it. Ideally, we'd
|
// 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
|
// 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
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
m.cfg.Save()
|
m.cfg.Save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Close removes the peer from the model and closes the underlying connection if possible.
|
// Close removes the peer from the model and closes the underlying connection if possible.
|
||||||
// Implements the protocol.Model interface.
|
// Implements the protocol.Model interface.
|
||||||
|
@ -258,6 +258,8 @@ func TestDeviceRename(t *testing.T) {
|
|||||||
ClientVersion: "v0.9.4",
|
ClientVersion: "v0.9.4",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer os.Remove("tmpconfig.xml")
|
||||||
|
|
||||||
cfg := config.New(device1)
|
cfg := config.New(device1)
|
||||||
cfg.Devices = []config.DeviceConfiguration{
|
cfg.Devices = []config.DeviceConfiguration{
|
||||||
{
|
{
|
||||||
@ -266,7 +268,7 @@ func TestDeviceRename(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db, _ := leveldb.Open(storage.NewMemStorage(), nil)
|
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 != "" {
|
if cfg.Devices[0].Name != "" {
|
||||||
t.Errorf("Device already has a name")
|
t.Errorf("Device already has a name")
|
||||||
}
|
}
|
||||||
@ -292,6 +294,15 @@ func TestDeviceRename(t *testing.T) {
|
|||||||
if cfg.Devices[0].Name != "tester" {
|
if cfg.Devices[0].Name != "tester" {
|
||||||
t.Errorf("Device name got overwritten")
|
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) {
|
func TestClusterConfig(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user