lib/model: Minor cleanup to not fondle cfg.Raw things in handleDeintroductions

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3739
This commit is contained in:
Jakob Borg
2016-11-17 08:56:55 +00:00
committed by Audrius Butkevicius
parent faee1d5a8d
commit a8a0bc356a
2 changed files with 36 additions and 24 deletions

View File

@@ -209,6 +209,27 @@ func (w *Wrapper) SetDevice(dev DeviceConfiguration) error {
return w.replaceLocked(newCfg)
}
// RemoveDevice removes the device from the configuration
func (w *Wrapper) RemoveDevice(id protocol.DeviceID) error {
w.mut.Lock()
defer w.mut.Unlock()
newCfg := w.cfg.Copy()
removed := false
for i := range newCfg.Devices {
if newCfg.Devices[i].DeviceID == id {
newCfg.Devices = append(newCfg.Devices[:i], newCfg.Devices[i+1:]...)
removed = true
break
}
}
if !removed {
return nil
}
return w.replaceLocked(newCfg)
}
// Folders returns a map of folders. Folder structures should not be changed,
// other than for the purpose of updating via SetFolder().
func (w *Wrapper) Folders() map[string]FolderConfiguration {