(rootDir: string, pointId: string)
| 71 | } |
| 72 | |
| 73 | export async function restorePoint(rootDir: string, pointId: string): Promise<string[]> { |
| 74 | const normalizedRoot = resolve(rootDir); |
| 75 | const manifest = await loadManifest(normalizedRoot); |
| 76 | const point = manifest.find((p) => p.id === pointId); |
| 77 | if (!point) throw new Error(`Restore point ${pointId} not found`); |
| 78 | |
| 79 | const backupDir = join(normalizedRoot, DATA_DIR, "backups", pointId); |
| 80 | const restoredFiles: string[] = []; |
| 81 | |
| 82 | for (const file of point.files) { |
| 83 | const targetPath = assertWithinRoot(normalizedRoot, file); |
| 84 | const backupPath = join(backupDir, file.replace(/[\\/]/g, "__")); |
| 85 | try { |
| 86 | const content = await readFile(backupPath, "utf-8"); |
| 87 | await mkdir(dirname(targetPath), { recursive: true }); |
| 88 | await writeFile(targetPath, content); |
| 89 | restoredFiles.push(file); |
| 90 | } catch { |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return restoredFiles; |
| 95 | } |
| 96 | |
| 97 | export async function listRestorePoints(rootDir: string): Promise<RestorePoint[]> { |
| 98 | return loadManifest(rootDir); |
no test coverage detected