Add folder update support and ClientData field.
[src/xds/xds-server.git] / lib / syncthing / folder-st.go
index ae95b27..74aa4bb 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
@@ -58,7 +62,7 @@ func (f *STFolder) Add(cfg folder.FolderConfig) (*folder.FolderConfig, error) {
        f.fConfig = cfg
 
        // Update Syncthing folder
-       // (expect if status is ErrorConfig)
+       // (except if status is ErrorConfig)
        // TODO: add cache to avoid multiple requests on startup
        if f.fConfig.Status != folder.StatusErrorConfig {
                id, err := f.st.FolderChange(f.fConfig)
@@ -139,6 +143,15 @@ func (f *STFolder) Remove() error {
        return err2
 }
 
+// Update update some fields of a folder
+func (f *STFolder) Update(cfg folder.FolderConfig) (*folder.FolderConfig, error) {
+       if f.fConfig.ID != cfg.ID {
+               return nil, fmt.Errorf("Invalid id")
+       }
+       f.fConfig = cfg
+       return &f.fConfig, nil
+}
+
 // RegisterEventChange requests registration for folder event change
 func (f *STFolder) RegisterEventChange(cb *folder.EventCB, data *folder.EventCBData) error {
        f.eventChangeCB = cb