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

Method indexFile

src/extraction/index.ts:3223–3271  ·  view source on GitHub ↗

* Index a single file

(relativePath: string)

Source from the content-addressed store, hash-verified

3221 * Index a single file
3222 */
3223 async indexFile(relativePath: string): Promise<ExtractionResult> {
3224 // Indexing read: follow in-root symlinks (the `../` guard still applies), #935.
3225 const fullPath = validatePathWithinRoot(this.rootDir, relativePath, { allowSymlinkEscape: true });
3226
3227 if (!fullPath) {
3228 return {
3229 nodes: [],
3230 edges: [],
3231 unresolvedReferences: [],
3232 errors: [{ message: `Path traversal blocked: ${relativePath}`, filePath: relativePath, severity: 'error', code: 'path_traversal' }],
3233 durationMs: 0,
3234 };
3235 }
3236
3237 // Read file content and stats
3238 let content: string;
3239 let stats: fs.Stats;
3240 try {
3241 // An oversize file is stored as skipped; its bytes are never needed (#1910).
3242 const read = await readBoundedSource(fullPath);
3243 stats = read.stats;
3244 // An MPEG transport stream named `.ts` is not TypeScript (#1910).
3245 if (read.bytes !== null && isMpegTsBytes(relativePath, read.bytes)) {
3246 return { nodes: [], edges: [], unresolvedReferences: [], errors: [], durationMs: 0 };
3247 }
3248 content = read.bytes === null ? oversizeStamp(stats.size) : read.bytes.toString('utf8');
3249 } catch (error) {
3250 // Nothing at the path: nothing to index, and not a read failure (#2904).
3251 if (isMissingPathError(error)) {
3252 return { nodes: [], edges: [], unresolvedReferences: [], errors: [], durationMs: 0 };
3253 }
3254 return {
3255 nodes: [],
3256 edges: [],
3257 unresolvedReferences: [],
3258 errors: [
3259 {
3260 message: `Failed to read file: ${error instanceof Error ? error.message : String(error)}`,
3261 filePath: relativePath,
3262 severity: 'error',
3263 code: 'read_error',
3264 },
3265 ],
3266 durationMs: 0,
3267 };
3268 }
3269
3270 return this.indexFileWithContent(relativePath, content, stats);
3271 }
3272
3273 /**
3274 * Index a single file with pre-read content and stats.

Callers 2

indexFilesMethod · 0.95
syncMethod · 0.95

Calls 6

indexFileWithContentMethod · 0.95
validatePathWithinRootFunction · 0.90
readBoundedSourceFunction · 0.90
oversizeStampFunction · 0.90
isMissingPathErrorFunction · 0.90
isMpegTsBytesFunction · 0.85

Tested by

no test coverage detected