Skip to content

Commit c367b53

Browse files
Added function to find file server from given filepath
1 parent b55c02d commit c367b53

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

internal/scheduler/fcfs/utils.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fcfs
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) {
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+
/* check if it's remote */
15+
if server.Remote != nil {
16+
return true, server.Remote.Host, server.Remote.Port, true
17+
}
18+
/* local filesystem */
19+
return false, "", 0, true
20+
}
21+
}
22+
23+
/* filesystem not found */
24+
return false, "", 0, false
25+
}

0 commit comments

Comments
 (0)