resolveAgentAbsPath resolves the absolute path to a file or directory in the workspace. If the path is relative, it will be resolved relative to the workspace's expanded directory. If the path is absolute, it will be returned as-is. If the path is relative and the workspace directory is not expanded
(workingDirectory, relOrAbsPath, agentOS string, local bool)
| 600 | // If the path is being resolved within the workspace, the path will be resolved |
| 601 | // relative to the current working directory. |
| 602 | func resolveAgentAbsPath(workingDirectory, relOrAbsPath, agentOS string, local bool) (string, error) { |
| 603 | switch { |
| 604 | case relOrAbsPath == "": |
| 605 | return workingDirectory, nil |
| 606 | |
| 607 | case relOrAbsPath == "~" || strings.HasPrefix(relOrAbsPath, "~/"): |
| 608 | return "", xerrors.Errorf("path %q requires expansion and is not supported, use an absolute path instead", relOrAbsPath) |
| 609 | |
| 610 | case local: |
| 611 | p, err := filepath.Abs(relOrAbsPath) |
| 612 | if err != nil { |
| 613 | return "", xerrors.Errorf("expand path: %w", err) |
| 614 | } |
| 615 | return p, nil |
| 616 | |
| 617 | case agentOS == "windows": |
| 618 | relOrAbsPath = unixToWindowsPath(relOrAbsPath) |
| 619 | switch { |
| 620 | case workingDirectory != "" && !isWindowsAbsPath(relOrAbsPath): |
| 621 | return windowsJoinPath(workingDirectory, relOrAbsPath), nil |
| 622 | case isWindowsAbsPath(relOrAbsPath): |
| 623 | return relOrAbsPath, nil |
| 624 | default: |
| 625 | return "", xerrors.Errorf("path %q not supported, use an absolute path instead", relOrAbsPath) |
| 626 | } |
| 627 | |
| 628 | // Note that we use `path` instead of `filepath` since we want Unix behavior. |
| 629 | case workingDirectory != "" && !path.IsAbs(relOrAbsPath): |
| 630 | return path.Join(workingDirectory, relOrAbsPath), nil |
| 631 | case path.IsAbs(relOrAbsPath): |
| 632 | return relOrAbsPath, nil |
| 633 | default: |
| 634 | return "", xerrors.Errorf("path %q not supported, use an absolute path instead", relOrAbsPath) |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | func doAsync(f func()) (wait func()) { |
| 639 | done := make(chan struct{}) |