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

Function visitFind

packages/shell/src/extras.ts:375–429  ·  view source on GitHub ↗
(
  path: string,
  root: string,
  depth: number,
  ops: TreeOps,
  options: StateFindOptions,
  pathMatcher: RegExp | null,
  nameMatcher: RegExp | null,
  types: Set<string> | null,
  results: StateFindEntry[]
)

Source from the content-addressed store, hash-verified

373}
374
375async function visitFind(
376 path: string,
377 root: string,
378 depth: number,
379 ops: TreeOps,
380 options: StateFindOptions,
381 pathMatcher: RegExp | null,
382 nameMatcher: RegExp | null,
383 types: Set<string> | null,
384 results: StateFindEntry[]
385): Promise<void> {
386 const stat = await ops.lstat(path);
387 if (!stat) return;
388 const name = path === "/" ? "/" : path.slice(path.lastIndexOf("/") + 1);
389 if (
390 matchesFind(
391 path,
392 name,
393 depth,
394 stat,
395 options,
396 pathMatcher,
397 nameMatcher,
398 types
399 )
400 ) {
401 results.push({
402 path,
403 name,
404 type: stat.type,
405 depth,
406 size: stat.size,
407 mtime: stat.mtime
408 });
409 }
410 if (stat.type === "directory") {
411 const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
412 if (depth >= maxDepth) return;
413 const entries = await ops.readdirWithFileTypes(path);
414 for (const entry of entries) {
415 const child = await ops.resolvePath(path, entry.name);
416 await visitFind(
417 child,
418 root,
419 depth + 1,
420 ops,
421 options,
422 pathMatcher,
423 nameMatcher,
424 types,
425 results
426 );
427 }
428 }
429}
430
431function matchesFind(
432 path: string,

Callers 1

findInTreeFunction · 0.85

Calls 4

matchesFindFunction · 0.85
lstatMethod · 0.65
readdirWithFileTypesMethod · 0.65
resolvePathMethod · 0.65

Tested by

no test coverage detected