From d94141ed7419867231a1050eb81c72bfd25003c6 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Mon, 28 Aug 2017 21:44:26 +0200 Subject: Fixed path convertion/mapping for in/out and for command args. Signed-off-by: Sebastien Douheret --- lib/syncthing/folder-st.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'lib/syncthing/folder-st.go') diff --git a/lib/syncthing/folder-st.go b/lib/syncthing/folder-st.go index da27062..a372b6f 100644 --- a/lib/syncthing/folder-st.go +++ b/lib/syncthing/folder-st.go @@ -3,6 +3,7 @@ package st import ( "fmt" "path/filepath" + "strings" "github.com/iotbzh/xds-server/lib/folder" "github.com/iotbzh/xds-server/lib/xdsconfig" @@ -93,7 +94,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,6 +105,28 @@ 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) -- cgit 1.2.3-korg