* Index specific files * * Uses a mutex to prevent concurrent indexing operations.
(filePaths: string[])
| 975 | * Uses a mutex to prevent concurrent indexing operations. |
| 976 | */ |
| 977 | async indexFiles(filePaths: string[]): Promise<IndexResult> { |
| 978 | return this.indexMutex.withLock(async () => { |
| 979 | try { |
| 980 | this.fileLock.acquire(); |
| 981 | } catch { |
| 982 | 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 }; |
| 983 | } |
| 984 | try { |
| 985 | // The files' nodes are new to the resolver: a resolution after this |
| 986 | // reloads its caches, the set of node names included, as indexAll and |
| 987 | // sync do before they resolve, instead of reading the graph as it was |
| 988 | // before (#2829). Awaited, so the write lock is held until the files |
| 989 | // are stored, as indexAll and sync hold it: returned unawaited, the |
| 990 | // promise left the `try` at once and the `finally` let the lock go as |
| 991 | // soon as indexing started, so another process could write meanwhile. |
| 992 | return await this.orchestrator.indexFiles(filePaths).finally(() => this.resolver.clearCaches()); |
| 993 | } finally { |
| 994 | this.fileLock.release(); |
| 995 | } |
| 996 | }); |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Sync with current file state (incremental update). |