- c.Log.Infoln("Share root directory: ", c.ShareRootDir)
-
- // FIXME - add a builder interface and support other builder type (eg. native)
- builderType := "syncthing"
-
- switch builderType {
- case "syncthing":
- // Syncthing settings only configurable from config.json file
- stGuiAddr := c.fileConf.SThgConf.GuiAddress
- stGuiApikey := c.fileConf.SThgConf.GuiAPIKey
- if stGuiAddr == "" {
- stGuiAddr = "http://localhost:8384"
- }
- if stGuiAddr[0:7] != "http://" {
- stGuiAddr = "http://" + stGuiAddr
- }
-
- // Retry if connection fail
- retry := 5
- for retry > 0 {
- c.SThg = st.NewSyncThing(stGuiAddr, stGuiApikey, c.Log)
- if c.SThg != nil {
- break
- }
- c.Log.Warningf("Establishing connection to Syncthing (retry %d/5)", retry)
- time.Sleep(time.Second)
- retry--
- }
- if c.SThg == nil {
- c.Log.Fatalf("ERROR: cannot connect to Syncthing (url: %s)", stGuiAddr)
- }
-
- // Retrieve Syncthing config
- id, err := c.SThg.IDGet()
- if err != nil {
- return Config{}, err
- }
-
- if c.Builder, err = NewBuilderConfig(id); err != nil {
- c.Log.Fatalln(err)
- }
-
- // Retrieve initial Syncthing config
- stCfg, err := c.SThg.ConfigGet()
- if err != nil {
- return Config{}, err
- }
- for _, stFld := range stCfg.Folders {
- relativePath := strings.TrimPrefix(stFld.RawPath, c.ShareRootDir)
- if relativePath == "" {
- relativePath = stFld.RawPath
- }
- newFld := NewFolderConfig(stFld.ID, stFld.Label, c.ShareRootDir, strings.Trim(relativePath, "/"))
- c.Folders = c.Folders.Update(FoldersConfig{newFld})
- }
-
- default:
- log.Fatalln("Unsupported builder type")
- }
-
- return c, nil
-}
-
-// GetFolderFromID retrieves the Folder config from id
-func (c *Config) GetFolderFromID(id string) *FolderConfig {
- if idx := c.Folders.GetIdx(id); idx != -1 {
- return &c.Folders[idx]
- }
- return nil
-}
-
-// UpdateAll updates all the current configuration
-func (c *Config) UpdateAll(newCfg Config) error {
- return fmt.Errorf("Not Supported")
- /*
- if err := VerifyConfig(newCfg); err != nil {
- return err
- }