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
  36639085_56c2_b6be_fa5a_bce73400fd8c["estimateDirectorySize()"]
  52a097f2_598d_df67_e422_55b20a202d95["zipRepository()"]
  52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 36639085_56c2_b6be_fa5a_bce73400fd8c
  dfe11f52_4dd3_db89_9717_941d05bae091["warn()"]
  36639085_56c2_b6be_fa5a_bce73400fd8c -->|calls| dfe11f52_4dd3_db89_9717_941d05bae091
  style 36639085_56c2_b6be_fa5a_bce73400fd8c 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;
}

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