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

Method refreshWatchTree

src/sync/watcher.ts:504–539  ·  view source on GitHub ↗

Reconcile logical directory paths with real targets, including retargeted links.

()

Source from the content-addressed store, hash-verified

502
503 /** Reconcile logical directory paths with real targets, including retargeted links. */
504 private refreshWatchTree(): void {
505 if (this.stopped || this.inert) return;
506 this.visitedRealDirs.clear();
507 const directories = new Map<string, string>();
508 const desired = new Map<string, string>();
509 const recursive = supportsRecursiveWatch();
510 const walk = (dir: string, linked: boolean): void => {
511 if (this.shouldIgnoreDir(dir)) return;
512 let real: string;
513 try {
514 real = fs.realpathSync(dir);
515 if (this.visitedRealDirs.has(real)) return;
516 this.visitedRealDirs.add(real);
517 directories.set(dir, real);
518 if (!recursive || linked) desired.set(dir, real);
519 for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
520 const child = path.join(dir, entry.name);
521 if (entry.isDirectory()) {
522 walk(child, false);
523 } else if (entry.isSymbolicLink()) {
524 // Follow directory symlinks just like the indexer's walk. Realpath
525 // deduplication includes ordinary directories and the root itself.
526 try {
527 if (fs.statSync(child).isDirectory()) walk(child, true);
528 } catch { /* broken link */ }
529 }
530 }
531 } catch { /* removed or unreadable directory */ }
532 };
533 walk(this.projectRoot, false);
534 this.knownDirs = directories;
535 for (const dir of this.dirWatchers.keys()) {
536 if (desired.get(dir) !== this.watchedRealDirs.get(dir)) this.unwatchDir(dir);
537 }
538 for (const [dir, real] of desired) this.watchDirectory(dir, real, recursive);
539 }
540
541 /** Coalesce directory topology events before walking; file edits never walk the tree. */
542 private scheduleTreeRefresh(): void {

Callers 3

startMethod · 0.95
startRecursiveMethod · 0.95
scheduleTreeRefreshMethod · 0.95

Calls 6

unwatchDirMethod · 0.95
watchDirectoryMethod · 0.95
supportsRecursiveWatchFunction · 0.85
getMethod · 0.65
walkFunction · 0.50
clearMethod · 0.45

Tested by

no test coverage detected