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

Method startIndexWatcher

src/ui-server/api/events.ts:377–398  ·  view source on GitHub ↗

* The index, through one watch on the data directory. * * Non-recursive and on the directory rather than the database file: SQLite * writes land in `codegraph.db-wal`, and a full re-index REPLACES * `codegraph.db` outright (a watch on the file itself would follow the * unlinked inode

()

Source from the content-addressed store, hash-verified

375 * unlinked inode and never fire again).
376 */
377 private startIndexWatcher(): void {
378 if (this.indexWatcher) return;
379 const dir = getCodeGraphDir(this.projectRoot);
380 try {
381 const watcher = fs.watch(dir, { persistent: false }, () => this.scheduleProbe());
382 watcher.on('error', () => {
383 // The data directory went away, or the OS dropped the watch. Nothing to
384 // retry against — a client that reloads gets a fresh one.
385 this.indexUp = false;
386 this.indexWatcher = null;
387 try {
388 watcher.close();
389 } catch {
390 /* already closed */
391 }
392 });
393 this.indexWatcher = watcher;
394 this.indexUp = true;
395 } catch {
396 this.indexUp = false;
397 }
398 }
399
400 /**
401 * Wait for the writing to stop, then look once.

Callers 1

ensureWatchingMethod · 0.95

Calls 5

scheduleProbeMethod · 0.95
getCodeGraphDirFunction · 0.90
watchMethod · 0.80
onMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected