feat(installer): add config backup utility for safe upgrades

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-08 13:26:27 +09:00
parent 7022a7e85d
commit 2f86a17516
+32
View File
@@ -0,0 +1,32 @@
import { copyFileSync, existsSync, mkdirSync } from "node:fs"
import { dirname } from "node:path"
export interface BackupResult {
success: boolean
backupPath?: string
error?: string
}
export function backupConfigFile(configPath: string): BackupResult {
if (!existsSync(configPath)) {
return { success: true }
}
const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
const backupPath = `${configPath}.backup-${timestamp}`
try {
const dir = dirname(backupPath)
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true })
}
copyFileSync(configPath, backupPath)
return { success: true, backupPath }
} catch (err) {
return {
success: false,
error: err instanceof Error ? err.message : "Failed to create backup",
}
}
}