lib/config, lib/model: Include paused folders in cluster config (fixes #4897)

This commit is contained in:
Simon Frei
2018-04-22 18:01:52 +02:00
committed by Audrius Butkevicius
parent 56cf2db68b
commit f6458d1b8f
5 changed files with 79 additions and 29 deletions

View File

@@ -325,13 +325,18 @@ func (cfg *Configuration) clean() error {
existingDevices[device.DeviceID] = true
}
// Ensure that the device list is free from duplicates
// Ensure that the device list is
// - free from duplicates
// - sorted by ID
cfg.Devices = ensureNoDuplicateDevices(cfg.Devices)
sort.Sort(DeviceConfigurationList(cfg.Devices))
// Ensure that any loose devices are not present in the wrong places
// Ensure that there are no duplicate devices
// Ensure that the versioning configuration parameter map is not nil
// Ensure that the folder list is sorted by ID
sort.Sort(FolderConfigurationList(cfg.Folders))
// Ensure that in all folder configs
// - any loose devices are not present in the wrong places
// - there are no duplicate devices
// - the versioning configuration parameter map is not nil
for i := range cfg.Folders {
cfg.Folders[i].Devices = ensureExistingDevices(cfg.Folders[i].Devices, existingDevices)
cfg.Folders[i].Devices = ensureNoDuplicateFolderDevices(cfg.Folders[i].Devices)

View File

@@ -278,3 +278,17 @@ func (l FolderDeviceConfigurationList) Len() int {
func (f *FolderConfiguration) CheckFreeSpace() (err error) {
return checkFreeSpace(f.MinDiskFree, f.Filesystem())
}
type FolderConfigurationList []FolderConfiguration
func (l FolderConfigurationList) Len() int {
return len(l)
}
func (l FolderConfigurationList) Less(a, b int) bool {
return l[a].ID < l[b].ID
}
func (l FolderConfigurationList) Swap(a, b int) {
l[a], l[b] = l[b], l[a]
}

View File

@@ -267,6 +267,13 @@ func (w *Wrapper) Folders() map[string]FolderConfiguration {
return w.folderMap
}
// FolderList returns a slice of folders.
func (w *Wrapper) FolderList() []FolderConfiguration {
w.mut.Lock()
defer w.mut.Unlock()
return append([]FolderConfiguration(nil), w.cfg.Folders...)
}
// SetFolder adds a new folder to the configuration, or overwrites an existing
// folder with the same ID.
func (w *Wrapper) SetFolder(fld FolderConfiguration) (Waiter, error) {