MCPcopy Create free account
hub / github.com/alibaba/open-code-review / resolveWorkspacePath

Method resolveWorkspacePath

internal/tool/filereader.go:91–113  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

89}
90
91func (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
115func (fr *FileReader) readFromGitShow(parentCtx context.Context, path string) (string, error) {
116 ctx, cancel := context.WithTimeout(parentCtx, 30*time.Second)

Callers 2

readFromDiskMethod · 0.95
readLinesFromDiskMethod · 0.95

Calls 2

CanonicalPathFunction · 0.92
WithinBaseFunction · 0.92

Tested by

no test coverage detected