CanonicalizePath takes a path and produces a canonical absolute path, performing any OS- or environment-specific path transformations (within the limitations of the Go standard library). If the path is empty, it returns the empty path with no error. If missingOk is true, then if the canonicalized
(path string, missingOk bool)
| 491 | // the empty path with no error. If missingOk is true, then if the |
| 492 | // canonicalized path does not exist, an absolute path is given instead. |
| 493 | func CanonicalizePath(path string, missingOk bool) (string, error) { |
| 494 | path, err := TranslateCygwinPath(path) |
| 495 | if err != nil { |
| 496 | return "", err |
| 497 | } |
| 498 | if len(path) > 0 { |
| 499 | path, err := filepath.Abs(path) |
| 500 | if err != nil { |
| 501 | return "", err |
| 502 | } |
| 503 | result, err := CanonicalizeSystemPath(path) |
| 504 | if err != nil && os.IsNotExist(err) && missingOk { |
| 505 | return path, nil |
| 506 | } |
| 507 | return result, err |
| 508 | } |
| 509 | return "", nil |
| 510 | } |
| 511 | |
| 512 | const ( |
| 513 | windowsPrefix = `.\` |