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

Method indexFiles

src/index.ts:1006–1026  ·  view source on GitHub ↗

* Index specific files * * Uses a mutex to prevent concurrent indexing operations.

(filePaths: string[])

Source from the content-addressed store, hash-verified

1004 * Uses a mutex to prevent concurrent indexing operations.
1005 */
1006 async indexFiles(filePaths: string[]): Promise<IndexResult> {
1007 return this.indexMutex.withLock(async () => {
1008 try {
1009 this.fileLock.acquire();
1010 } catch {
1011 return { success: false, filesIndexed: 0, filesSkipped: 0, filesErrored: 0, nodesCreated: 0, edgesCreated: 0, errors: [{ message: 'Could not acquire file lock - another process may be indexing', severity: 'error' as const }], durationMs: 0 };
1012 }
1013 try {
1014 // The files' nodes are new to the resolver: a resolution after this
1015 // reloads its caches, the set of node names included, as indexAll and
1016 // sync do before they resolve, instead of reading the graph as it was
1017 // before (#2829). Awaited, so the write lock is held until the files
1018 // are stored, as indexAll and sync hold it: returned unawaited, the
1019 // promise left the `try` at once and the `finally` let the lock go as
1020 // soon as indexing started, so another process could write meanwhile.
1021 return await this.orchestrator.indexFiles(filePaths).finally(() => this.resolver.clearCaches());
1022 } finally {
1023 this.fileLock.release();
1024 }
1025 });
1026 }
1027
1028 /**
1029 * Sync with current file state (incremental update).

Calls 4

clearCachesMethod · 0.80
releaseMethod · 0.65
withLockMethod · 0.45
acquireMethod · 0.45

Tested by 1

interruptAfterExtractionFunction · 0.36