Delete folders on disk (Server side and for Syncthing folder only)
[src/xds/xds-server.git] / lib / syncthing / folder-st.go
index da27062..7e1fe55 100644 (file)
@@ -2,7 +2,9 @@ package st
 
 import (
        "fmt"
+       "os"
        "path/filepath"
+       "strings"
 
        "github.com/iotbzh/xds-server/lib/folder"
        "github.com/iotbzh/xds-server/lib/xdsconfig"
@@ -93,7 +95,7 @@ func (f *STFolder) GetConfig() folder.FolderConfig {
        return f.fConfig
 }
 
-// GetFullPath returns the full path
+// GetFullPath returns the full path of a directory (from server POV)
 func (f *STFolder) GetFullPath(dir string) string {
        if &dir == nil {
                dir = ""
@@ -104,9 +106,39 @@ func (f *STFolder) GetFullPath(dir string) string {
        return filepath.Join(f.fConfig.RootPath, f.fConfig.ClientPath, dir)
 }
 
+// ConvPathCli2Svr Convert path from Client to Server
+func (f *STFolder) ConvPathCli2Svr(s string) string {
+       if f.fConfig.ClientPath != "" && f.fConfig.RootPath != "" {
+               return strings.Replace(s,
+                       f.fConfig.ClientPath,
+                       f.fConfig.RootPath+"/"+f.fConfig.ClientPath,
+                       -1)
+       }
+       return s
+}
+
+// ConvPathSvr2Cli Convert path from Server to Client
+func (f *STFolder) ConvPathSvr2Cli(s string) string {
+       if f.fConfig.ClientPath != "" && f.fConfig.RootPath != "" {
+               return strings.Replace(s,
+                       f.fConfig.RootPath+"/"+f.fConfig.ClientPath,
+                       f.fConfig.ClientPath,
+                       -1)
+       }
+       return s
+}
+
 // Remove a folder
 func (f *STFolder) Remove() error {
-       return f.st.FolderDelete(f.stfConfig.ID)
+       err := f.st.FolderDelete(f.stfConfig.ID)
+
+       // Delete folder on server side
+       err2 := os.RemoveAll(f.GetFullPath(""))
+
+       if err != nil {
+               return err
+       }
+       return err2
 }
 
 // RegisterEventChange requests registration for folder event change