resolvePath converts a path to an absolute, symlink-resolved form. If the file does not exist, falls back to filepath.Abs so the caller can still arm an ancestor directory.
(p string)
| 401 | // form. If the file does not exist, falls back to filepath.Abs so |
| 402 | // the caller can still arm an ancestor directory. |
| 403 | func resolvePath(p string) string { |
| 404 | if p == "" { |
| 405 | return "" |
| 406 | } |
| 407 | if abs, err := filepath.Abs(p); err == nil { |
| 408 | // EvalSymlinks fails on non-existent paths. Resolve as |
| 409 | // far as possible without erroring out: walk up until |
| 410 | // we find an existing ancestor, eval its symlinks, and |
| 411 | // re-join the trailing segments. |
| 412 | if resolved, err := filepath.EvalSymlinks(abs); err == nil { |
| 413 | return resolved |
| 414 | } |
| 415 | return resolvePathBestEffort(abs) |
| 416 | } |
| 417 | return "" |
| 418 | } |
| 419 | |
| 420 | func resolvePathBestEffort(abs string) string { |
| 421 | dir := filepath.Dir(abs) |
no test coverage detected