(filePath: string)
| 2 | import path from "path" |
| 3 | |
| 4 | export async function backupFile(filePath: string): Promise<string | null> { |
| 5 | if (!(await pathExists(filePath))) return null |
| 6 | |
| 7 | try { |
| 8 | const timestamp = new Date().toISOString().replace(/[:.]/g, "-") |
| 9 | const backupPath = `${filePath}.bak.${timestamp}` |
| 10 | await fs.copyFile(filePath, backupPath) |
| 11 | return backupPath |
| 12 | } catch { |
| 13 | return null |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | export async function pathExists(filePath: string): Promise<boolean> { |
| 18 | try { |
no test coverage detected