MCPcopy
hub / github.com/colbymchenry/codegraph / validateDirectory

Function validateDirectory

src/directory.ts:585–617  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

583 * Check if the .codegraph directory has valid structure
584 */
585export function validateDirectory(projectRoot: string): {
586 valid: boolean;
587 errors: string[];
588} {
589 const errors: string[] = [];
590 const codegraphDir = getCodeGraphDir(projectRoot);
591
592 if (!fs.existsSync(codegraphDir)) {
593 errors.push('CodeGraph directory does not exist');
594 return { valid: false, errors };
595 }
596
597 if (!fs.statSync(codegraphDir).isDirectory()) {
598 errors.push('.codegraph exists but is not a directory');
599 return { valid: false, errors };
600 }
601
602 // Auto-repair / upgrade .gitignore (non-critical file). A missing one is
603 // recreated; a stale pre-wildcard default that never ignored daemon.pid is
604 // regenerated in place (issue #788); a user-authored file is left alone.
605 const gitignorePath = path.join(codegraphDir, '.gitignore');
606 const existedBefore = fs.existsSync(gitignorePath);
607 if (!ensureGitignore(gitignorePath) && !existedBefore) {
608 // Only a missing-and-uncreatable file is surfaced; a failed in-place
609 // upgrade of an existing file is non-fatal — the index still works.
610 errors.push('.gitignore missing in .codegraph directory and could not be created');
611 }
612
613 return {
614 valid: errors.length === 0,
615 errors,
616 };
617}

Callers 3

openMethod · 0.90
openSyncMethod · 0.90
foundation.test.tsFile · 0.90

Calls 3

getCodeGraphDirFunction · 0.85
ensureGitignoreFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected