X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fsyncthing%2Fst.go;h=8fd50d3e386efc4693fb267be020857b7578a59e;hb=f53cc64ea17876c7ad8f088fc069448b2414b808;hp=5976e2f769c25fb273ffec032888f47ab3ddd03e;hpb=a50baa7c309f7eb55fe87c71f4c688ace325b6ac;p=src%2Fxds%2Fxds-agent.git
diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go
index 5976e2f..8fd50d3 100644
--- a/lib/syncthing/st.go
+++ b/lib/syncthing/st.go
@@ -169,13 +169,45 @@ func (s *SyncThing) Start() (*exec.Cmd, error) {
env := []string{
"STNODEFAULTFOLDER=1",
+ "STNOUPGRADE=1",
+ "STNORESTART=1",
+ }
+
+ // XXX - temporary hack because -gui-apikey seems to correctly handle by
+ // syncthing the early first time
+ stConfigFile := filepath.Join(s.Home, "config.xml")
+ if s.APIKey != "" && !common.Exists(stConfigFile) {
+ s.log.Infof("Stop and restart Syncthing (hack for apikey setting)")
+ s.STCmd, err = s.startProc("syncthing", args, env, &s.exitSTChan)
+ tmo := 20
+ for ; tmo > 0; tmo-- {
+ s.log.Debugf("Waiting Syncthing config.xml creation (%v)\n", tmo)
+ time.Sleep(500 * time.Millisecond)
+ if common.Exists(stConfigFile) {
+ break
+ }
+ }
+ if tmo <= 0 {
+ return nil, fmt.Errorf("Cannot start Syncthing for config file creation")
+ }
+ s.Stop()
+ read, err := ioutil.ReadFile(stConfigFile)
+ if err != nil {
+ return nil, fmt.Errorf("Cannot read Syncthing config file for apikey setting")
+ }
+ re := regexp.MustCompile(`.*`)
+ newContents := re.ReplaceAllString(string(read), ""+s.APIKey+"")
+ err = ioutil.WriteFile(stConfigFile, []byte(newContents), 0)
+ if err != nil {
+ return nil, fmt.Errorf("Cannot write Syncthing config file to set apikey")
+ }
}
s.STCmd, err = s.startProc("syncthing", args, env, &s.exitSTChan)
// Use autogenerated apikey if not set by config.json
if s.APIKey == "" {
- if fd, err := os.Open(filepath.Join(s.Home, "config.xml")); err == nil {
+ if fd, err := os.Open(stConfigFile); err == nil {
defer fd.Close()
if b, err := ioutil.ReadAll(fd); err == nil {
re := regexp.MustCompile("(.*)")