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

Function normalizePath

packages/shell/src/filesystem.ts:1571–1588  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

1569}
1570
1571function normalizePath(path: string): string {
1572 if (!path.startsWith("/")) path = "/" + path;
1573 const parts = path.split("/");
1574 const resolved: string[] = [];
1575 for (const part of parts) {
1576 if (part === "" || part === ".") continue;
1577 if (part === "..") {
1578 resolved.pop();
1579 } else {
1580 resolved.push(part);
1581 }
1582 }
1583 const result = "/" + resolved.join("/");
1584 if (result.length > MAX_PATH_LENGTH) {
1585 throw new Error(`ENAMETOOLONG: path exceeds ${MAX_PATH_LENGTH} characters`);
1586 }
1587 return result;
1588}
1589
1590function getParent(path: string): string {
1591 const normalized = normalizePath(path);

Callers 15

resolveSymlinkMethod · 0.70
symlinkMethod · 0.70
readlinkMethod · 0.70
lstatMethod · 0.70
statMethod · 0.70
readFileMethod · 0.70
readFileBytesMethod · 0.70
writeFileBytesMethod · 0.70
writeFileMethod · 0.70
readFileStreamMethod · 0.70
appendFileMethod · 0.70
deleteFileMethod · 0.70

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected