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)
| 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'. |
| 42 | func 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 |
no outgoing calls