Home / Function/ estimateDirectorySize() — mcp Function Reference

estimateDirectorySize() — mcp Function Reference

Architecture documentation for the estimateDirectorySize() function in zip-repository.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  ee32b175_3040_f03e_0439_e4935b9ba1ca["estimateDirectorySize()"]
  1fd46af5_c3e2_8998_1eb2_098430ff3629["zipRepository()"]
  1fd46af5_c3e2_8998_1eb2_098430ff3629 -->|calls| ee32b175_3040_f03e_0439_e4935b9ba1ca
  e5352615_c5fb_64a2_cc5c_a248578cbc8a["warn()"]
  ee32b175_3040_f03e_0439_e4935b9ba1ca -->|calls| e5352615_c5fb_64a2_cc5c_a248578cbc8a
  style ee32b175_3040_f03e_0439_e4935b9ba1ca fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/utils/zip-repository.ts lines 346–413

async function estimateDirectorySize(
  rootDir: string,
  ignoreFilter: Ignore
): Promise<number> {
  let totalSize = 0;

  async function walkDirectory(currentDir: string): Promise<void> {
    let entries: string[];

    try {
      entries = await fs.readdir(currentDir);
    } catch (error: any) {
      if (error.code === 'EACCES') {
        logger.warn('Permission denied:', currentDir);
        return;
      }
      throw error;
    }

    for (const entry of entries) {
      const fullPath = join(currentDir, entry);
      const relativePath = relative(rootDir, fullPath);

      // Normalize path for ignore matching (use forward slashes)
      const normalizedRelativePath = relativePath.split(sep).join('/');

      // Check if ignored
      if (ignoreFilter.ignores(normalizedRelativePath)) {
        continue;
      }

      let stats;
      try {
        stats = await fs.lstat(fullPath);
      } catch (error: any) {
        if (error.code === 'ENOENT') {
          // File disappeared, skip
          continue;
        }
        logger.warn('Failed to stat:', fullPath, error.message);
        continue;
      }

      // Skip symlinks to prevent following links outside the repository
      if (stats.isSymbolicLink()) {
        continue;
      }

      if (stats.isDirectory()) {
        // Check if directory itself should be ignored
        const dirPath = normalizedRelativePath + '/';
        if (ignoreFilter.ignores(dirPath)) {
          continue;
        }

        // Recurse into directory
        await walkDirectory(fullPath);
      } else if (stats.isFile()) {
        // Add file size to total
        totalSize += stats.size;
      }
      // Skip other special files (sockets, FIFOs, etc.)
    }
  }

  await walkDirectory(rootDir);
  return totalSize;
}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does estimateDirectorySize() do?
estimateDirectorySize() is a function in the mcp codebase.
What does estimateDirectorySize() call?
estimateDirectorySize() calls 1 function(s): warn.
What calls estimateDirectorySize()?
estimateDirectorySize() is called by 1 function(s): zipRepository.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free