(rootDir: string, files: string[], message: string)
| 45 | } |
| 46 | |
| 47 | export async function createRestorePoint(rootDir: string, files: string[], message: string): Promise<RestorePoint> { |
| 48 | const normalizedRoot = resolve(rootDir); |
| 49 | const dataPath = await ensureDataDir(normalizedRoot); |
| 50 | const id = `rp-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; |
| 51 | const backupDir = join(dataPath, "backups", id); |
| 52 | await mkdir(backupDir, { recursive: true }); |
| 53 | |
| 54 | for (const file of files) { |
| 55 | const fullPath = assertWithinRoot(normalizedRoot, file); |
| 56 | try { |
| 57 | const content = await readFile(fullPath, "utf-8"); |
| 58 | const backupPath = join(backupDir, file.replace(/[\\/]/g, "__")); |
| 59 | await writeFile(backupPath, content); |
| 60 | } catch { |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const point: RestorePoint = { id, timestamp: Date.now(), files, message }; |
| 65 | const manifest = await loadManifest(normalizedRoot); |
| 66 | manifest.push(point); |
| 67 | if (manifest.length > 100) manifest.splice(0, manifest.length - 100); |
| 68 | await saveManifest(normalizedRoot, manifest); |
| 69 | |
| 70 | return point; |
| 71 | } |
| 72 | |
| 73 | export async function restorePoint(rootDir: string, pointId: string): Promise<string[]> { |
| 74 | const normalizedRoot = resolve(rootDir); |
no test coverage detected