lib/model: Simplify access to Folder and Device configuration. (#7151)

Use the accessor methods with a device argument instead of looking up
in a temporary map of the same data.
This commit is contained in:
André Colomb 2020-11-24 22:20:50 +01:00 committed by GitHub
parent 6c7e8c08db
commit e6595c1ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1044,7 +1044,7 @@ func (m *model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
}
changed := false
deviceCfg, ok := m.cfg.Devices()[deviceID]
deviceCfg, ok := m.cfg.Device(deviceID)
if !ok {
l.Debugln("Device disappeared from config while processing cluster-config")
return errDeviceUnknown
@ -1381,7 +1381,7 @@ func (m *model) handleIntroductions(introducerCfg config.DeviceConfiguration, cm
foldersDevices.set(device.ID, folder.ID)
if _, ok := m.cfg.Devices()[device.ID]; !ok {
if _, ok := m.cfg.Device(device.ID); !ok {
// The device is currently unknown. Add it to the config.
devices[device.ID] = m.introduceDevice(device, introducerCfg)
} else if fcfg.SharedWith(device.ID) {
@ -1834,7 +1834,7 @@ func (m *model) GetIgnores(folder string) ([]string, []string, error) {
m.fmut.RUnlock()
if !cfgOk {
cfg, cfgOk = m.cfg.Folders()[folder]
cfg, cfgOk = m.cfg.Folder(folder)
if !cfgOk {
return nil, nil, fmt.Errorf("folder %s does not exist", folder)
}
@ -1861,7 +1861,7 @@ func (m *model) GetIgnores(folder string) ([]string, []string, error) {
}
func (m *model) SetIgnores(folder string, content []string) error {
cfg, ok := m.cfg.Folders()[folder]
cfg, ok := m.cfg.Folder(folder)
if !ok {
return fmt.Errorf("folder %s does not exist", cfg.Description())
}