MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / validateDirectory

Function validateDirectory

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

Source from the content-addressed store, hash-verified

838 * Check if the .codegraph directory has valid structure
839 */
840export function validateDirectory(projectRoot: string): {
841 valid: boolean;
842 errors: string[];
843} {
844 const errors: string[] = [];
845 const codegraphDir = getCodeGraphDir(projectRoot);
846
847 if (!fs.existsSync(codegraphDir)) {
848 errors.push('CodeGraph directory does not exist');
849 return { valid: false, errors };
850 }
851
852 if (!fs.statSync(codegraphDir).isDirectory()) {
853 errors.push('.codegraph exists but is not a directory');
854 return { valid: false, errors };
855 }
856
857 // Auto-repair / upgrade .gitignore (non-critical file). A missing one is
858 // recreated; a stale pre-wildcard default that never ignored daemon.pid is
859 // regenerated in place (issue #788); a user-authored file is left alone.
860 const gitignorePath = path.join(codegraphDir, '.gitignore');
861 const existedBefore = fs.existsSync(gitignorePath);
862 if (!ensureGitignore(gitignorePath) && !existedBefore) {
863 // Only a missing-and-uncreatable file is surfaced; a failed in-place
864 // upgrade of an existing file is non-fatal — the index still works.
865 errors.push('.gitignore missing in .codegraph directory and could not be created');
866 }
867
868 return {
869 valid: errors.length === 0,
870 errors,
871 };
872}

Callers 3

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

Calls 3

getCodeGraphDirFunction · 0.85
ensureGitignoreFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected