lib/config: Error on empty folder path (fixes #5853) (#5854)

This commit is contained in:
Simon Frei
2019-07-14 11:03:14 +02:00
committed by Jakob Borg
parent f1a7dd766e
commit def4b8cee5
8 changed files with 39 additions and 28 deletions

View File

@@ -10,6 +10,7 @@ package config
import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
"io/ioutil"
@@ -91,6 +92,12 @@ var (
}
)
var (
errFolderIDEmpty = errors.New("folder has empty ID")
errFolderIDDuplicate = errors.New("folder has duplicate ID")
errFolderPathEmpty = errors.New("folder has empty path")
)
func New(myID protocol.DeviceID) Configuration {
var cfg Configuration
cfg.Version = CurrentVersion
@@ -273,12 +280,17 @@ func (cfg *Configuration) clean() error {
folder.prepare()
if folder.ID == "" {
return fmt.Errorf("folder with empty ID in configuration")
return errFolderIDEmpty
}
if folder.Path == "" {
return fmt.Errorf("folder %q: %v", folder.ID, errFolderPathEmpty)
}
if _, ok := existingFolders[folder.ID]; ok {
return fmt.Errorf("duplicate folder ID %q in configuration", folder.ID)
return fmt.Errorf("folder %q: %v", folder.ID, errFolderIDDuplicate)
}
existingFolders[folder.ID] = folder
}