(path string)
| 89 | } |
| 90 | |
| 91 | func (fr *FileReader) resolveWorkspacePath(path string) (string, error) { |
| 92 | repoRoot, err := pathutil.CanonicalPath(fr.RepoDir) |
| 93 | if err != nil { |
| 94 | return "", fmt.Errorf("resolve repository path %q: %w", fr.RepoDir, err) |
| 95 | } |
| 96 | |
| 97 | fullPath := filepath.Join(repoRoot, path) |
| 98 | if !pathutil.WithinBase(repoRoot, fullPath) { |
| 99 | return "", fmt.Errorf("file path %q is outside repository", path) |
| 100 | } |
| 101 | |
| 102 | resolvedPath, err := filepath.EvalSymlinks(fullPath) |
| 103 | if err != nil { |
| 104 | if os.IsNotExist(err) { |
| 105 | return fullPath, nil |
| 106 | } |
| 107 | return "", fmt.Errorf("resolve file %q: %w", path, err) |
| 108 | } |
| 109 | if !pathutil.WithinBase(repoRoot, resolvedPath) { |
| 110 | return "", fmt.Errorf("file path %q is outside repository", path) |
| 111 | } |
| 112 | return resolvedPath, nil |
| 113 | } |
| 114 | |
| 115 | func (fr *FileReader) readFromGitShow(parentCtx context.Context, path string) (string, error) { |
| 116 | ctx, cancel := context.WithTimeout(parentCtx, 30*time.Second) |
no test coverage detected