feat: 升级至 v0.3.16 — 工单修复 51 项 + 审查修复 30 项(安全加固/适配器/工具系统/数据层/前端)
This commit is contained in:
@@ -1208,6 +1208,37 @@ export function registerAllIPCHandlers(
|
||||
return { success: true, inherited, failed };
|
||||
});
|
||||
|
||||
// #51 修复: 校验源数据库完整性,防止继承损坏的数据库(如 WAL 损坏)导致新工作空间数据丢失
|
||||
// 在前端勾选 inheritDatabase 时调用,执行 PRAGMA integrity_check
|
||||
ipcMain.handle('workspace:checkDatabaseIntegrity', async (_event, sourcePath: string) => {
|
||||
if (!sourcePath) return { success: false, error: '参数无效' };
|
||||
const { existsSync } = await import('fs');
|
||||
const { resolve } = await import('path');
|
||||
const srcFile = join(resolve(sourcePath), '.metona', 'agent.db');
|
||||
if (!existsSync(srcFile)) {
|
||||
// 源数据库不存在不算损坏(可能是新工作空间尚未创建数据库),视为校验通过
|
||||
return { success: true, ok: true, detail: 'source database not exist' };
|
||||
}
|
||||
try {
|
||||
const Database = (await import('better-sqlite3')).default;
|
||||
// 以只读方式打开源库,避免锁竞争
|
||||
const db = new Database(srcFile, { readonly: true, fileMustExist: true });
|
||||
try {
|
||||
const result = db.prepare('PRAGMA integrity_check').get() as { integrity_check: string };
|
||||
const ok = result.integrity_check === 'ok';
|
||||
if (!ok) {
|
||||
log.warn(`[WORKSPACE] Source database integrity check failed: ${result.integrity_check} (source=${sourcePath})`);
|
||||
}
|
||||
return { success: true, ok, detail: result.integrity_check };
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
} catch (err) {
|
||||
log.error(`[WORKSPACE] Failed to check database integrity: ${(err as Error).message}`);
|
||||
return { success: false, error: (err as Error).message };
|
||||
}
|
||||
});
|
||||
|
||||
// 获取当前工作空间详情:路径 + 2 个核心文件状态 + 自动目录状态
|
||||
ipcMain.handle('workspace:getInfo', async () => {
|
||||
const { existsSync, statSync, readFileSync, readdirSync } = await import('fs');
|
||||
|
||||
Reference in New Issue
Block a user