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