X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fsyncthing%2Fstfolder.go;h=ca001a3b8064a0412cd7e164e23b58e976bc7c2e;hb=5dc2ff003106f0ced38caadb06033f24c792f9b9;hp=503ba4b36c7ff5dff631a9f666a1fd203c8d419a;hpb=a3d2ca72d05d28b1ae5820787ff696dd75fd17cc;p=src%2Fxds%2Fxds-server.git diff --git a/lib/syncthing/stfolder.go b/lib/syncthing/stfolder.go index 503ba4b..ca001a3 100644 --- a/lib/syncthing/stfolder.go +++ b/lib/syncthing/stfolder.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package st import ( @@ -6,13 +23,13 @@ import ( "path/filepath" "strings" - "github.com/iotbzh/xds-server/lib/folder" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1" stconfig "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/protocol" ) // FolderLoadFromStConfig Load/Retrieve folder config from syncthing database -func (s *SyncThing) FolderLoadFromStConfig(f *[]folder.FolderConfig) error { +func (s *SyncThing) FolderLoadFromStConfig(f *[]xsapiv1.FolderConfig) error { defaultSdk := "" // cannot know which was the default sdk @@ -36,15 +53,15 @@ func (s *SyncThing) FolderLoadFromStConfig(f *[]folder.FolderConfig) error { if cliPath == "" { cliPath = stFld.Path } - *f = append(*f, folder.FolderConfig{ + *f = append(*f, xsapiv1.FolderConfig{ ID: stFld.ID, Label: stFld.Label, ClientPath: strings.TrimRight(cliPath, "/"), - Type: folder.TypeCloudSync, - Status: folder.StatusDisable, + Type: xsapiv1.TypeCloudSync, + Status: xsapiv1.StatusDisable, DefaultSdk: defaultSdk, RootPath: s.conf.FileConf.ShareRootDir, - DataCloudSync: folder.CloudSyncConfig{SyncThingID: devID}, + DataCloudSync: xsapiv1.CloudSyncConfig{SyncThingID: devID}, }) } @@ -52,7 +69,13 @@ func (s *SyncThing) FolderLoadFromStConfig(f *[]folder.FolderConfig) error { } // FolderChange is called when configuration has changed -func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { +func (s *SyncThing) FolderChange(f xsapiv1.FolderConfig) (string, error) { + var label, id string + + if id = f.ID; id == "" { + s.log.Errorf("Try to create Syncthing folder with null ID: %v", f) + return "", fmt.Errorf("Cannot create Syncthing folder (ID must be set") + } // Get current config stCfg, err := s.ConfigGet() @@ -87,13 +110,9 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { } // Add or update Folder settings - var label, id string if label = f.Label; label == "" { label = strings.Split(id, "/")[0] } - if id = f.ID; id == "" { - id = stClientID[0:15] + "_" + label - } folder := stconfig.FolderConfiguration{ ID: id,