Skip to content

Commit 44b4786

Browse files
Find file server with path
1 parent 0e3d43a commit 44b4786

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

internal/transprocessor/utils.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package transprocessor
2+
3+
import (
4+
"strings"
5+
6+
"github.com/PythonHacker24/linux-acl-management-backend/config"
7+
)
8+
9+
func FindServerFromPath(servers []config.FileSystemServers, filepath string) (isRemote bool, host string, port int, found bool, absolutePath string) {
10+
/* search through all the servers */
11+
for _, server := range servers {
12+
/* check if the server path has the prefix for filepath */
13+
if strings.HasPrefix(filepath, server.Path) {
14+
absolutePath := strings.TrimPrefix(filepath, server.Path)
15+
/* check if it's remote */
16+
if server.Remote != nil {
17+
return true, server.Remote.Host, server.Remote.Port, true, absolutePath
18+
}
19+
/* local filesystem */
20+
return false, "", 0, true, absolutePath
21+
}
22+
}
23+
24+
/* filesystem not found */
25+
return false, "", 0, false, ""
26+
}

0 commit comments

Comments
 (0)