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

Method handleDirEvent

src/sync/watcher.ts:604–637  ·  view source on GitHub ↗

Events are relative to a watch's logical path, even for an external target.

(dir: string, filename: string | Buffer | null)

Source from the content-addressed store, hash-verified

602
603 /** Events are relative to a watch's logical path, even for an external target. */
604 private handleDirEvent(dir: string, filename: string | Buffer | null): void {
605 if (this.stopped) return;
606 if (filename == null) {
607 this.scheduleTreeRefresh();
608 return;
609 }
610 const name = String(filename);
611 // Names are relative to the watched folder. An absolute one is the folder
612 // itself, reported gone (see armGoneCheck); this is all a normal event pays.
613 if (path.isAbsolute(name)) {
614 this.armGoneCheck(dir);
615 return;
616 }
617 const full = path.join(dir, name);
618 const rel = normalizePath(path.relative(this.projectRoot, full));
619 if (!rel || rel === '.') {
620 this.scheduleTreeRefresh();
621 return;
622 }
623 // Churn under an ignored directory (node_modules, dist, .git) is dropped
624 // before any per-event fs call; `.git/info/exclude` still reaches the scope
625 // refresh in handleChange (#1728).
626 if (rel !== '.git/info/exclude' && this.shouldIgnoreDir(path.dirname(full))) return;
627 try {
628 if (fs.statSync(full).isDirectory()) {
629 if (this.shouldIgnoreDir(full)) return;
630 // Existing directory notifications can represent a retargeted link.
631 if (this.knownDirs.get(full) !== fs.realpathSync(full)) this.scheduleTreeRefresh();
632 return;
633 }
634 } catch { /* deleted/inaccessible */ }
635 if (this.knownDirs.has(full) && !this.shouldIgnoreDir(full)) this.scheduleTreeRefresh();
636 this.handleChange(rel);
637 }
638
639 /**
640 * Shared change handler for both watch strategies. `rel` is a

Callers 2

startRecursiveMethod · 0.95
watchDirectoryMethod · 0.95

Calls 8

scheduleTreeRefreshMethod · 0.95
armGoneCheckMethod · 0.95
shouldIgnoreDirMethod · 0.95
handleChangeMethod · 0.95
normalizePathFunction · 0.90
hasMethod · 0.80
getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected