fix(installer,cli): refuse to index $HOME / filesystem root (#860)
Running the installer or `codegraph init`/`index` from $HOME auto-indexed the entire home tree (installer indexes process.cwd() with no guard), producing a multi-GB ~/.codegraph/codegraph.db; the install dir sharing the ~/.codegraph name then made every home subdir resolve its root to $HOME. On pre-1.0 macOS the per-file watcher over that tree exhausted kern.maxfiles and crashed the machine (#845; the fd blowup was fixed in 1.0.0, this fixes the root cause). Add unsafeIndexRootReason() and refuse the home dir, a parent of home, and filesystem roots at the installer auto-index, `init`, and `index`. Overridable with --force. Closes #845.
This commit is contained in:
+13
-1
@@ -28,7 +28,7 @@ import { getGlyphs } from '../ui/glyphs';
|
||||
// installer must stay importable even when native modules can't load).
|
||||
import { watchDisabledReason } from '../sync/watch-policy';
|
||||
import { isGitRepo, isSyncHookInstalled, installGitSyncHook } from '../sync/git-hooks';
|
||||
import { getCodeGraphDir, codeGraphDirName } from '../directory';
|
||||
import { getCodeGraphDir, codeGraphDirName, unsafeIndexRootReason } from '../directory';
|
||||
import { getTelemetry, recordIndexEvent, TELEMETRY_DOCS } from '../telemetry';
|
||||
|
||||
// Backwards-compat: keep these named exports — downstream code may
|
||||
@@ -501,6 +501,18 @@ async function initializeLocalProject(
|
||||
): Promise<void> {
|
||||
const projectPath = process.cwd();
|
||||
|
||||
// Never auto-index the home directory or a filesystem root. Running the
|
||||
// installer from `$HOME` would otherwise index the entire home tree — a
|
||||
// multi-GB index, constant watcher churn, and (pre-1.0 on macOS) fd
|
||||
// exhaustion that crashed the machine (#845). The install itself still
|
||||
// completes; we just skip the auto-index and point them at a real project.
|
||||
const unsafe = unsafeIndexRootReason(projectPath);
|
||||
if (unsafe) {
|
||||
clack.log.warn(`Skipping automatic indexing — ${projectPath} looks like ${unsafe}.`);
|
||||
clack.log.info('Indexing it would pull in caches, other projects, and your whole tree. Run "codegraph init" inside a specific project instead.');
|
||||
return;
|
||||
}
|
||||
|
||||
let CodeGraph: typeof import('../index').default;
|
||||
try {
|
||||
CodeGraph = (await import('../index')).default;
|
||||
|
||||
Reference in New Issue
Block a user