From 6749d0825bf73b52a3dcca40ab7768533d712d19 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 6 Sep 2026 00:14:09 +0000 Subject: [PATCH] fix(installer): fail safely on history backup errors Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com> --- tools/install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/install.sh b/tools/install.sh index bdfb5c3b0..ef060791d 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -417,6 +417,14 @@ setup_zshrc() { hist_backup="${hist}.pre-oh-my-zsh" if [ -e "$hist_backup" ]; then hist_backup="${hist_backup}-$(date +%Y-%m-%d_%H-%M-%S)" + if [ -e "$hist_backup" ]; then + fmt_error "$hist_backup exists. Can't back up $hist" + fmt_error "re-run the installer again in a couple of seconds" + if ! mv "$OLD_ZSHRC" "$zdot/.zshrc"; then + fmt_error "could not restore $zdot/.zshrc from backup" + fi + exit 1 + fi fi if cp "$hist" "$hist_backup"; then echo "${FMT_GREEN}Backing up your command history to ${hist_backup}${FMT_RESET}" @@ -425,6 +433,10 @@ setup_zshrc() { # a half-written file would look like a usable backup rm -f "$hist_backup" fmt_error "could not back up $hist" + if ! mv "$OLD_ZSHRC" "$zdot/.zshrc"; then + fmt_error "could not restore $zdot/.zshrc from backup" + fi + exit 1 fi done fi