MCPcopy Create free account
hub / github.com/cloudflare/agents / realpath

Method realpath

packages/shell/src/workspace.ts:133–152  ·  view source on GitHub ↗
(path: string, _depth = 0)

Source from the content-addressed store, hash-verified

131 }
132
133 async realpath(path: string, _depth = 0): Promise<string> {
134 if (_depth > MAX_SYMLINK_DEPTH) {
135 throw new Error(`ELOOP: too many levels of symbolic links: ${path}`);
136 }
137
138 const stat = await this.ws.lstat(path);
139 if (!stat) {
140 throw new Error(`ENOENT: no such file or directory: ${path}`);
141 }
142
143 if (stat.type !== "symlink") {
144 return normalizePath(path);
145 }
146
147 const target = await this.ws.readlink(path);
148 const resolved = target.startsWith("/")
149 ? normalizePath(target)
150 : normalizePath(`${dirname(path)}/${target}`);
151 return this.realpath(resolved, _depth + 1);
152 }
153
154 resolvePath(base: string, path: string): string {
155 return normalizePath(path.startsWith("/") ? path : `${base}/${path}`);

Callers

nothing calls this directly

Calls 4

normalizePathFunction · 0.70
dirnameFunction · 0.70
lstatMethod · 0.65
readlinkMethod · 0.65

Tested by

no test coverage detected