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/folder/folder-interface.go | 2 ++ lib/folder/folder-pathmap.go | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/folder') diff --git a/lib/folder/folder-interface.go b/lib/folder/folder-interface.go index c04cbd7..4beccb8 100644 --- a/lib/folder/folder-interface.go +++ b/lib/folder/folder-interface.go @@ -27,6 +27,8 @@ type IFOLDER interface { Add(cfg FolderConfig) (*FolderConfig, error) // Add a new folder GetConfig() FolderConfig // Get folder public configuration GetFullPath(dir string) string // Get folder full path + ConvPathCli2Svr(s string) string // Convert path from Client to Server + ConvPathSvr2Cli(s string) string // Convert path from Server to Client Remove() error // Remove a folder RegisterEventChange(cb *EventCB, data *EventCBData) error // Request events registration (sent through WS) UnRegisterEventChange() error // Un-register events diff --git a/lib/folder/folder-pathmap.go b/lib/folder/folder-pathmap.go index f73f271..1020026 100644 --- a/lib/folder/folder-pathmap.go +++ b/lib/folder/folder-pathmap.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" common "github.com/iotbzh/xds-common/golib" "github.com/iotbzh/xds-server/lib/xdsconfig" @@ -80,7 +81,7 @@ func (f *PathMap) GetConfig() FolderConfig { return f.config } -// GetFullPath returns the full path +// GetFullPath returns the full path of a directory (from server POV) func (f *PathMap) GetFullPath(dir string) string { if &dir == nil { return f.config.DataPathMap.ServerPath @@ -88,6 +89,28 @@ func (f *PathMap) GetFullPath(dir string) string { return filepath.Join(f.config.DataPathMap.ServerPath, dir) } +// ConvPathCli2Svr Convert path from Client to Server +func (f *PathMap) ConvPathCli2Svr(s string) string { + if f.config.ClientPath != "" && f.config.DataPathMap.ServerPath != "" { + return strings.Replace(s, + f.config.ClientPath, + f.config.DataPathMap.ServerPath, + -1) + } + return s +} + +// ConvPathSvr2Cli Convert path from Server to Client +func (f *PathMap) ConvPathSvr2Cli(s string) string { + if f.config.ClientPath != "" && f.config.DataPathMap.ServerPath != "" { + return strings.Replace(s, + f.config.DataPathMap.ServerPath, + f.config.ClientPath, + -1) + } + return s +} + // Remove a folder func (f *PathMap) Remove() error { // nothing to do -- cgit 1.2.3-korg