X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fsyncthing%2Fstfolder.go;h=196e3c7ec1e702d9d3f8990fc35678740c5296c9;hb=4695555e178bcabe54c5bf82117c9c4cef5440b5;hp=a5312eb4ed9174fef0ccd2afa0357e341920bf1a;hpb=97ca1f277dc8b6973d6fa67add5593a9c395ce60;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/syncthing/stfolder.go b/lib/syncthing/stfolder.go index a5312eb..196e3c7 100644 --- a/lib/syncthing/stfolder.go +++ b/lib/syncthing/stfolder.go @@ -10,15 +10,52 @@ import ( "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 *[]XdsFolderConfig) error { + + defaultSdk := "" // cannot know which was the default sdk + + stCfg, err := s.ConfigGet() + if err != nil { + return err + } + if len(stCfg.Devices) < 1 { + return fmt.Errorf("Cannot load syncthing config: no device defined") + } + devID := stCfg.Devices[0].DeviceID.String() + if devID == s.MyID { + if len(stCfg.Devices) < 2 { + return fmt.Errorf("Cannot load syncthing config: no valid device found") + } + devID = stCfg.Devices[1].DeviceID.String() + } + + for _, stFld := range stCfg.Folders { + *f = append(*f, XdsFolderConfig{ + ID: stFld.ID, + Label: stFld.Label, + ClientPath: strings.TrimRight(stFld.Path, "/"), + Type: XdsTypeCloudSync, + Status: StatusDisable, + DefaultSdk: defaultSdk, + RootPath: "", + DataCloudSync: XdsCloudSyncConfig{SyncThingID: devID}, + }) + } + + return nil +} +*/ + // FolderChange is called when configuration has changed func (s *SyncThing) FolderChange(f FolderChangeArg) (string, error) { @@ -29,16 +66,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"}, } @@ -59,7 +97,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 @@ -67,13 +105,11 @@ 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, Label: label, - RawPath: pathCli, + Path: pathCli, AutoNormalize: true, } @@ -102,11 +138,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