aboutsummaryrefslogtreecommitdiffstats
path: root/lib/syncthing/st.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/syncthing/st.go')
-rw-r--r--lib/syncthing/st.go50
1 files changed, 6 insertions, 44 deletions
diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go
index 3380cda..9bdb48f 100644
--- a/lib/syncthing/st.go
+++ b/lib/syncthing/st.go
@@ -32,6 +32,7 @@ type SyncThing struct {
Home string
STCmd *exec.Cmd
STICmd *exec.Cmd
+ MyID string
// Private fields
binDir string
@@ -211,13 +212,13 @@ func (s *SyncThing) Start() (*exec.Cmd, error) {
env := []string{
"STNODEFAULTFOLDER=1",
"STNOUPGRADE=1",
- "STNORESTART=1",
+ "STNORESTART=1", // FIXME SEB remove ?
}
s.STCmd, err = s.startProc("syncthing", args, env, &s.exitSTChan)
// Use autogenerated apikey if not set by config.json
- if s.APIKey == "" {
+ if err == nil && s.APIKey == "" {
if fd, err := os.Open(filepath.Join(s.Home, "config.xml")); err == nil {
defer fd.Close()
if b, err := ioutil.ReadAll(fd); err == nil {
@@ -314,7 +315,9 @@ func (s *SyncThing) Connect() error {
s.client.SetLogger(s.log)
- return nil
+ s.MyID, err = s.IDGet()
+
+ return err
}
// IDGet returns the Syncthing ID of Syncthing instance running locally
@@ -360,44 +363,3 @@ func (s *SyncThing) IsConfigInSync() (bool, error) {
}
return d.ConfigInSync, nil
}
-
-// FolderStatus Returns all information about the current
-func (s *SyncThing) FolderStatus(folderID string) (*FolderStatus, error) {
- var data []byte
- var res FolderStatus
- if folderID == "" {
- return nil, fmt.Errorf("folderID not set")
- }
- if err := s.client.HTTPGet("db/status?folder="+folderID, &data); err != nil {
- return nil, err
- }
- if err := json.Unmarshal(data, &res); err != nil {
- return nil, err
- }
- return &res, nil
-}
-
-// IsFolderInSync Returns true when folder is in sync
-func (s *SyncThing) IsFolderInSync(folderID string) (bool, error) {
- // FIXME better to detected FolderCompletion event (/rest/events)
- // See https://docs.syncthing.net/dev/events.html
- sts, err := s.FolderStatus(folderID)
- if err != nil {
- return false, err
- }
- return sts.NeedBytes == 0, nil
-}
-
-// FolderScan Request immediate folder scan.
-// Scan all folders if folderID param is empty
-func (s *SyncThing) FolderScan(folderID string, subpath string) error {
- url := "db/scan"
- if folderID != "" {
- url += "?folder=" + folderID
-
- if subpath != "" {
- url += "&sub=" + subpath
- }
- }
- return s.client.HTTPPost(url, "")
-}