Skip to content

Commit 0cae785

Browse files
grypezclaude
andcommitted
feat(kernel-store): support absolute database paths
Modify `getDBFilename` to detect and pass through absolute paths unchanged, instead of always joining them with the base directory. This enables the daemon to store its database at a fixed location outside the default relative path (e.g. `~/.ocap/kernel.db`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 670daf6 commit 0cae785

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

packages/kernel-store/src/sqlite/nodejs.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ describe('makeSQLKernelDatabase', () => {
200200
recursive: true,
201201
});
202202
});
203+
204+
it('returns absolute path as-is and ensures parent directory exists', async () => {
205+
const result = await getDBFilename('/home/user/.ocap/store.db');
206+
expect(result).toBe('/home/user/.ocap/store.db');
207+
expect(mockMkdir).toHaveBeenCalledWith('/home/user/.ocap', {
208+
recursive: true,
209+
});
210+
});
203211
});
204212

205213
describe('savepoint functionality', () => {

packages/kernel-store/src/sqlite/nodejs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Database as SqliteDatabase } from 'better-sqlite3';
33
import Sqlite from 'better-sqlite3';
44
import { mkdir } from 'node:fs/promises';
55
import { tmpdir } from 'node:os';
6-
import { join } from 'node:path';
6+
import { dirname, isAbsolute, join } from 'node:path';
77

88
import {
99
SQL_QUERIES,
@@ -334,6 +334,10 @@ export async function getDBFilename(label: string): Promise<string> {
334334
if (label.startsWith(':')) {
335335
return label;
336336
}
337+
if (isAbsolute(label)) {
338+
await mkdir(dirname(label), { recursive: true });
339+
return label;
340+
}
337341
const dbRoot = join(tmpdir(), './ocap-sqlite', getDBFolder());
338342
await mkdir(dbRoot, { recursive: true });
339343
return join(dbRoot, label);

0 commit comments

Comments
 (0)