MCPcopy Create free account
hub / github.com/docker-exec/dexec / SanitisePath

Function SanitisePath

util/util.go:42–54  ·  view source on GitHub ↗

SanitisePath takes an absolute path as provided by filepath.Abs() and makes it ready to be passed to Docker based on the current OS. So far the only OS format that requires transforming is Windows which is provided in the form 'C:\some\path' but Docker requires '/c/some/path'.

(path string, platform string)

Source from the content-addressed store, hash-verified

40// the only OS format that requires transforming is Windows which is provided
41// in the form 'C:\some\path' but Docker requires '/c/some/path'.
42func SanitisePath(path string, platform string) string {
43 sanitised := path
44 if platform == "windows" {
45 windowsPathPattern := regexp.MustCompile("^([A-Za-z]):(.*)")
46 match := windowsPathPattern.FindStringSubmatch(path)
47
48 driveLetter := strings.ToLower(match[1])
49 pathRemainder := strings.Replace(match[2], "\\", "/", -1)
50
51 sanitised = fmt.Sprintf(sanitisedWindowsPathPattern, driveLetter, pathRemainder)
52 }
53 return sanitised
54}
55
56// RetrievePath takes an array whose first element may contain an overridden
57// path and converts either this, or the default of "." to an absolute path

Callers 2

TestSanitisePathFunction · 0.85
RetrievePathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSanitisePathFunction · 0.68