diff options
Diffstat (limited to 'lib/syncthing')
-rw-r--r-- | lib/syncthing/folder-st.go | 10 | ||||
-rw-r--r-- | lib/syncthing/st.go | 18 | ||||
-rw-r--r-- | lib/syncthing/stfolder.go | 24 |
3 files changed, 27 insertions, 25 deletions
diff --git a/lib/syncthing/folder-st.go b/lib/syncthing/folder-st.go index 7e1fe55..f25a505 100644 --- a/lib/syncthing/folder-st.go +++ b/lib/syncthing/folder-st.go @@ -39,7 +39,11 @@ func (f *STFolder) NewUID(suffix string) string { if i > 15 { i = 15 } - return uuid.NewV1().String()[:14] + f.st.MyID[:i] + "_" + suffix + uuid := uuid.NewV1().String()[:14] + f.st.MyID[:i] + if len(suffix) > 0 { + uuid += "_" + suffix + } + return uuid } // Add a new folder @@ -57,10 +61,8 @@ func (f *STFolder) Add(cfg folder.FolderConfig) (*folder.FolderConfig, error) { f.fConfig = cfg - f.fConfig.DataCloudSync.BuilderSThgID = f.st.MyID // FIXME - should be removed after local ST config rework - // Update Syncthing folder - // (expect if status is ErrorConfig) + // (except if status is ErrorConfig) // TODO: add cache to avoid multiple requests on startup if f.fConfig.Status != folder.StatusErrorConfig { id, err := f.st.FolderChange(f.fConfig) diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go index 99a17a1..d1ebbe6 100644 --- a/lib/syncthing/st.go +++ b/lib/syncthing/st.go @@ -34,16 +34,16 @@ type SyncThing struct { STICmd *exec.Cmd MyID string Connected bool + Events *Events // Private fields binDir string logsDir string exitSTChan chan ExitChan exitSTIChan chan ExitChan - conf *xdsconfig.Config client *common.HTTPClient log *logrus.Logger - Events *Events + conf *xdsconfig.Config } // ExitChan Channel used for process exit @@ -134,7 +134,8 @@ func (s *SyncThing) startProc(exeName string, args []string, env []string, eChan // Kill existing process (useful for debug ;-) ) if os.Getenv("DEBUG_MODE") != "" { - exec.Command("bash", "-c", "pkill -9 "+exeName).Output() + fmt.Printf("\n!!! DEBUG_MODE set: KILL existing %s process(es) !!!\n", exeName) + exec.Command("bash", "-c", "ps -ax |grep "+exeName+" |grep "+s.BaseURL+" |cut -d' ' -f 1|xargs -I{} kill -9 {}").Output() } // When not set (or set to '.') set bin to path of xds-agent executable @@ -227,7 +228,6 @@ func (s *SyncThing) Start() (*exec.Cmd, error) { env := []string{ "STNODEFAULTFOLDER=1", "STNOUPGRADE=1", - "STNORESTART=1", // FIXME SEB remove ? } s.STCmd, err = s.startProc("syncthing", args, env, &s.exitSTChan) @@ -317,7 +317,12 @@ func (s *SyncThing) Connect() error { common.HTTPClientConfig{ URLPrefix: "/rest", HeaderClientKeyName: "X-Syncthing-ID", + LogOut: s.conf.LogVerboseOut, + LogPrefix: "SYNCTHING: ", + LogLevel: common.HTTPLogLevelWarning, }) + s.client.SetLogLevel(s.log.Level.String()) + if err != nil { msg := ": " + err.Error() if strings.Contains(err.Error(), "connection refused") { @@ -329,11 +334,6 @@ func (s *SyncThing) Connect() error { return fmt.Errorf("ERROR: cannot connect to Syncthing (null client)") } - // Redirect HTTP log into a file - s.client.SetLogLevel(s.conf.Log.Level.String()) - s.client.LoggerPrefix = "SYNCTHING: " - s.client.LoggerOut = s.conf.LogVerboseOut - s.MyID, err = s.IDGet() if err != nil { return fmt.Errorf("ERROR: cannot retrieve ID") diff --git a/lib/syncthing/stfolder.go b/lib/syncthing/stfolder.go index 70ac70a..503ba4b 100644 --- a/lib/syncthing/stfolder.go +++ b/lib/syncthing/stfolder.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/iotbzh/xds-server/lib/folder" - "github.com/syncthing/syncthing/lib/config" + stconfig "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/protocol" ) @@ -32,9 +32,9 @@ func (s *SyncThing) FolderLoadFromStConfig(f *[]folder.FolderConfig) error { } for _, stFld := range stCfg.Folders { - cliPath := strings.TrimPrefix(stFld.RawPath, s.conf.FileConf.ShareRootDir) + cliPath := strings.TrimPrefix(stFld.Path, s.conf.FileConf.ShareRootDir) if cliPath == "" { - cliPath = stFld.RawPath + cliPath = stFld.Path } *f = append(*f, folder.FolderConfig{ ID: stFld.ID, @@ -69,7 +69,7 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { return "", err } - newDevice := config.DeviceConfiguration{ + newDevice := stconfig.DeviceConfiguration{ DeviceID: devID, Name: stClientID, Addresses: []string{"dynamic"}, @@ -95,22 +95,22 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { id = stClientID[0:15] + "_" + label } - folder := config.FolderConfiguration{ - ID: id, - Label: label, - RawPath: filepath.Join(s.conf.FileConf.ShareRootDir, f.ClientPath), + folder := stconfig.FolderConfiguration{ + ID: id, + Label: label, + Path: filepath.Join(s.conf.FileConf.ShareRootDir, f.ClientPath), } if s.conf.FileConf.SThgConf.RescanIntervalS > 0 { folder.RescanIntervalS = s.conf.FileConf.SThgConf.RescanIntervalS } - folder.Devices = append(folder.Devices, config.FolderDeviceConfiguration{ + folder.Devices = append(folder.Devices, stconfig.FolderDeviceConfiguration{ DeviceID: newDevice.DeviceID, }) found = false - var fld config.FolderConfiguration + var fld stconfig.FolderConfiguration for _, fld = range stCfg.Folders { if folder.ID == fld.ID { fld = folder @@ -155,8 +155,8 @@ func (s *SyncThing) FolderDelete(id string) error { } // FolderConfigGet Returns the configuration of a specific folder -func (s *SyncThing) FolderConfigGet(folderID string) (config.FolderConfiguration, error) { - fc := config.FolderConfiguration{} +func (s *SyncThing) FolderConfigGet(folderID string) (stconfig.FolderConfiguration, error) { + fc := stconfig.FolderConfiguration{} if folderID == "" { return fc, fmt.Errorf("folderID not set") } |