Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/pi-fff/src/aux-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface AuxPicker {
}

export interface AuxOpts {
frecencyDbPath?: string;
historyDbPath?: string;
enableFsRootScanning: boolean;
}

Expand Down Expand Up @@ -69,10 +67,11 @@ export class AuxFinderPool {
}

const { FileFinder } = await loadSdk();
// LMDB env can only be opened once per process; the main finder already
// owns the frecency/history DBs. Aux finders are transient and run without
// persistent scoring — see issue #700.
const result = FileFinder.create({
basePath: maybeRoot,
frecencyDbPath: this.opts.frecencyDbPath,
historyDbPath: this.opts.historyDbPath,
aiMode: true,
enableHomeDirScanning: true,
enableFsRootScanning: this.opts.enableFsRootScanning,
Expand Down
2 changes: 0 additions & 2 deletions packages/pi-fff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ export default function fffExtension(pi: ExtensionAPI) {
}

let auxPool = new AuxFinderPool({
frecencyDbPath,
historyDbPath,
enableFsRootScanning,
});

Expand Down
26 changes: 22 additions & 4 deletions packages/pi-fff/test/aux-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface MockFinder {
}

const created: MockFinder[] = [];
const createOptions: Record<string, unknown>[] = [];

function createMockFinder(basePath: string): MockFinder {
const finder: MockFinder = {
Expand All @@ -24,10 +25,13 @@ function createMockFinder(basePath: string): MockFinder {

const finderModule = {
FileFinder: {
create: (options: { basePath: string }) => ({
ok: true,
value: createMockFinder(options.basePath),
}),
create: (options: Record<string, unknown>) => {
createOptions.push(options);
return {
ok: true,
value: createMockFinder(options.basePath as string),
};
},
},
};

Expand All @@ -38,6 +42,7 @@ const { AuxFinderPool } = await import("../src/aux-finders");

function makePool() {
created.length = 0;
createOptions.length = 0;
return new AuxFinderPool({ enableFsRootScanning: false });
}

Expand Down Expand Up @@ -86,4 +91,17 @@ describe("AuxFinderPool covering reuse", () => {
expect(other.root).toBe("/a/b");
expect(created.length).toBe(2);
});

// Regression for #700: aux finders must not reopen the main frecency/history
// LMDB envs, or heed fails with "environment already open in this program".
test("aux finders are created without frecency/history db paths", async () => {
const pool = makePool();
await pool.acquire("/a/b/c");
await pool.acquire("/x/y");
expect(createOptions.length).toBe(2);
for (const opts of createOptions) {
expect(opts.frecencyDbPath).toBeUndefined();
expect(opts.historyDbPath).toBeUndefined();
}
});
});
Loading