Fixed folder ID and label generation.
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Mon, 6 Nov 2017 09:50:12 +0000 (10:50 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Mon, 6 Nov 2017 15:00:04 +0000 (16:00 +0100)
Folder ID is now a simple uuid (without sub-string of label)

lib/folder/folder-interface.go
lib/folder/folder-pathmap.go
lib/folder/folder-st-disable.go
lib/model/folders.go
lib/syncthing/folder-st.go

index aec773d..9eb6829 100644 (file)
@@ -60,9 +60,11 @@ type FolderConfig struct {
 
 // PathMapConfig Path mapping specific data
 type PathMapConfig struct {
-       ServerPath   string `json:"serverPath"`
-       CheckFile    string `json:"checkFile"`
-       CheckContent string `json:"checkContent"`
+       ServerPath string `json:"serverPath"`
+
+       // Don't keep temporary file name (IOW we don't want to save it and reuse it)
+       CheckFile    string `json:"checkFile" xml:"-"`
+       CheckContent string `json:"checkContent" xml:"-"`
 }
 
 // CloudSyncConfig CloudSync (AKA Syncthing) specific data
index bc714dd..e200164 100644 (file)
@@ -33,7 +33,11 @@ func NewFolderPathMap(gc *xdsconfig.Config) *PathMap {
 
 // NewUID Get a UUID
 func (f *PathMap) NewUID(suffix string) string {
-       return uuid.NewV1().String() + "_" + suffix
+       uuid := uuid.NewV1().String()
+       if len(suffix) > 0 {
+               uuid += "_" + suffix
+       }
+       return uuid
 }
 
 // Add a new folder
index f90b776..7b53ca8 100644 (file)
@@ -25,7 +25,11 @@ func NewFolderSTDisable(gc *xdsconfig.Config) *STFolderDisable {
 
 // NewUID Get a UUID
 func (f *STFolderDisable) NewUID(suffix string) string {
-       return uuid.NewV1().String() + "_" + suffix
+       uuid := uuid.NewV1().String()
+       if len(suffix) > 0 {
+               uuid += "_" + suffix
+       }
+       return uuid
 }
 
 // Add a new folder
index 24ac48c..d5ea3bf 100644 (file)
@@ -213,24 +213,23 @@ func (f *Folders) createUpdate(newF folder.FolderConfig, create bool, initial bo
                return nil, fmt.Errorf("Unsupported folder type")
        }
 
+       // Allocate a new UUID
+       if create {
+               newF.ID = fld.NewUID("")
+       }
+       if !create && newF.ID == "" {
+               return nil, fmt.Errorf("Cannot update folder with null ID")
+       }
+
        // Set default value if needed
        if newF.Status == "" {
                newF.Status = folder.StatusDisable
        }
        if newF.Label == "" {
-               newF.Label = filepath.Base(newF.ClientPath) + "_" + newF.ID[0:8]
-       }
-
-       // Allocate a new UUID
-       if create {
-               i := len(newF.Label)
-               if i > 20 {
-                       i = 20
+               newF.Label = filepath.Base(newF.ClientPath)
+               if len(newF.ID) > 8 {
+                       newF.Label += "_" + newF.ID[0:8]
                }
-               newF.ID = fld.NewUID(newF.Label[:i])
-       }
-       if !create && newF.ID == "" {
-               return nil, fmt.Errorf("Cannot update folder with null ID")
        }
 
        // Normalize path (needed for Windows path including bashlashes)
index 27a43e6..f25a505 100644 (file)
@@ -39,7 +39,11 @@ func (f *STFolder) NewUID(suffix string) string {
        if i > 15 {
                i = 15
        }
-       return uuid.NewV1().String()[:14] + f.st.MyID[:i] + "_" + suffix
+       uuid := uuid.NewV1().String()[:14] + f.st.MyID[:i]
+       if len(suffix) > 0 {
+               uuid += "_" + suffix
+       }
+       return uuid
 }
 
 // Add a new folder