X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fsyncthing%2Fstfolder.go;h=94d278cd4fb4077c618eb27f06009bce1b980f70;hb=247bb7c2db5f0d48178398599348249bf886ebbc;hp=d5c74ef00b0facacc2d502f8a577d32569e59fe1;hpb=d917dcca04b8d5f5a7a4fdf82d0a66ef14611fca;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/syncthing/stfolder.go b/lib/syncthing/stfolder.go index d5c74ef..94d278c 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 ( @@ -5,23 +22,22 @@ import ( "fmt" "strings" - common "github.com/iotbzh/xds-common/golib" - "github.com/iotbzh/xds-server/lib/folder" + common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git" stconfig "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/protocol" ) -// FIXME remove and use an interface on xdsconfig.FolderConfig +// FolderChangeArg argument structure used by FolderChange type FolderChangeArg struct { ID string Label string RelativePath string SyncThingID string - ShareRootDir string } // 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 @@ -41,26 +57,21 @@ func (s *SyncThing) FolderLoadFromStConfig(f *[]folder.FolderConfig) error { } for _, stFld := range stCfg.Folders { - /* - cliPath := strings.TrimPrefix(stFld.Path, s.conf.FileConf.ShareRootDir) - if cliPath == "" { - cliPath = stFld.Path - }*/ - 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, + ClientPath: strings.TrimRight(stFld.Path, "/"), + Type: xsapiv1.TypeCloudSync, + Status: StatusDisable, DefaultSdk: defaultSdk, - RootPath: "", //s.conf.FileConf.ShareRootDir, - DataCloudSync: folder.CloudSyncConfig{SyncThingID: devID}, + RootPath: "", + DataCloudSync: xsapiv1.CloudSyncConfig{SyncThingID: devID}, }) } return nil } +*/ // FolderChange is called when configuration has changed func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { @@ -72,16 +83,17 @@ func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { return "", err } + stClientID := f.SyncThingID // Add new Device if needed var devID protocol.DeviceID - if err := devID.UnmarshalText([]byte(f.SyncThingID)); err != nil { + if err := devID.UnmarshalText([]byte(stClientID)); err != nil { s.log.Errorf("not a valid device id (err %v)", err) return "", err } newDevice := stconfig.DeviceConfiguration{ DeviceID: devID, - Name: f.SyncThingID, + Name: stClientID, Addresses: []string{"dynamic"}, } @@ -102,7 +114,7 @@ func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { label = strings.Split(id, "/")[0] } if id = f.ID; id == "" { - id = f.SyncThingID[0:15] + "_" + label + id = stClientID[0:15] + "_" + label } // Resolve local path @@ -110,8 +122,6 @@ func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { if err != nil { pathCli = f.RelativePath } - // SEB still need ShareRootDir ? a sup - // pathCli := filepath.Join(f.ShareRootDir, f.RelativePath) folder := stconfig.FolderConfiguration{ ID: id, @@ -145,11 +155,8 @@ func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { } err = s.ConfigSet(stCfg) - if err != nil { - s.log.Errorln(err) - } - return id, nil + return id, err } // FolderDelete is called to delete a folder config