From 2f86a17516ee33a348b7bf4c73e61d8cb81ef2d3 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 8 Apr 2026 13:26:27 +0900 Subject: [PATCH] feat(installer): add config backup utility for safe upgrades Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/cli/config-manager/backup-config.ts | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/cli/config-manager/backup-config.ts diff --git a/src/cli/config-manager/backup-config.ts b/src/cli/config-manager/backup-config.ts new file mode 100644 index 000000000..682c5dd55 --- /dev/null +++ b/src/cli/config-manager/backup-config.ts @@ -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", + } + } +}