MCPcopy Index your code
hub / github.com/jetify-com/devbox / JoinPathLists

Function JoinPathLists

internal/devbox/envpath/pathlists.go:16–38  ·  view source on GitHub ↗

JoinPathLists joins and cleans PATH-style strings of [os.ListSeparator] delimited paths. To clean a path list, it splits it and does the following for each element: 1. Applies [filepath.Clean]. 2. Removes the path if it's relative (must begin with '/' and not be '.'). 3. Removes the path if it's a

(pathLists ...string)

Source from the content-addressed store, hash-verified

14// 2. Removes the path if it's relative (must begin with '/' and not be '.').
15// 3. Removes the path if it's a duplicate.
16func JoinPathLists(pathLists ...string) string {
17 if len(pathLists) == 0 {
18 return ""
19 }
20
21 seen := make(map[string]bool)
22 var cleaned []string
23 for _, path := range pathLists {
24 for _, path := range filepath.SplitList(path) {
25 path = filepath.Clean(path)
26 if path == "." || path[0] != '/' {
27 // Remove empty paths and don't allow relative
28 // paths for security reasons.
29 continue
30 }
31 if !seen[path] {
32 cleaned = append(cleaned, path)
33 }
34 seen[path] = true
35 }
36 }
37 return strings.Join(cleaned, string(filepath.ListSeparator))
38}
39
40func RemoveFromPath(path, pathToRemove string) string {
41 paths := filepath.SplitList(path)

Callers 4

computeEnvMethod · 0.92
TestCleanEnvPathFunction · 0.85
PathMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestCleanEnvPathFunction · 0.68