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

Function buildTreeNode

packages/shell/src/extras.ts:327–354  ·  view source on GitHub ↗
(
  path: string,
  depth: number,
  maxDepth: number,
  ops: TreeOps
)

Source from the content-addressed store, hash-verified

325}
326
327async function buildTreeNode(
328 path: string,
329 depth: number,
330 maxDepth: number,
331 ops: TreeOps
332): Promise<StateTreeNode> {
333 const stat = await ops.lstat(path);
334 if (!stat) {
335 throw new Error(`ENOENT: no such file or directory: ${path}`);
336 }
337 const node: StateTreeNode = {
338 path,
339 name: path === "/" ? "/" : path.slice(path.lastIndexOf("/") + 1),
340 type: stat.type,
341 size: stat.size
342 };
343 if (stat.type === "directory" && depth < maxDepth) {
344 const entries = await ops.readdirWithFileTypes(path);
345 node.children = [];
346 for (const entry of entries) {
347 const childPath = await ops.resolvePath(path, entry.name);
348 node.children.push(
349 await buildTreeNode(childPath, depth + 1, maxDepth, ops)
350 );
351 }
352 }
353 return node;
354}
355
356function summarizeNode(
357 node: StateTreeNode,

Callers 1

buildTreeFunction · 0.85

Calls 3

lstatMethod · 0.65
readdirWithFileTypesMethod · 0.65
resolvePathMethod · 0.65

Tested by

no test coverage detected