Fix invalid rootPath when creating a new project.
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Sat, 13 May 2017 21:13:42 +0000 (23:13 +0200)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Sat, 13 May 2017 21:13:42 +0000 (23:13 +0200)
lib/xdsconfig/config.go
lib/xdsconfig/folderconfig.go

index df98439..801891b 100644 (file)
@@ -186,6 +186,12 @@ func (c *Config) UpdateAll(newCfg Config) error {
 
 // UpdateFolder updates a specific folder into the current configuration
 func (c *Config) UpdateFolder(newFolder FolderConfig) (FolderConfig, error) {
+       // rootPath should not be empty
+       if newFolder.rootPath == "" {
+               newFolder.rootPath = c.ShareRootDir
+       }
+
+       // Sanity check of folder settings
        if err := FolderVerify(newFolder); err != nil {
                return FolderConfig{}, err
        }
index e8bff4f..f22e76f 100644 (file)
@@ -70,6 +70,10 @@ func FolderVerify(fCfg FolderConfig) error {
                err = fmt.Errorf("device id not set (SyncThingID field)")
        }
 
+       if fCfg.rootPath == "" {
+               err = fmt.Errorf("rootPath must not be empty")
+       }
+
        if err != nil {
                fCfg.Status = FolderStatusErrorConfig
                log.Printf("ERROR FolderVerify: %v\n", err)