From 8a0b98525cd282eb5562ead9785494069fe1c50c Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 4 Jan 2026 23:17:42 +0800 Subject: [PATCH] fix(install): implement atomic update to prevent binary corruption - Use temporary files (*.new) during installation process - Perform atomic 'mv -f' operation to replace binaries - Prevent partial updates if process is interrupted/fails - Fixes critical issue where failed update deleted existing app --- bin/uninstall.sh | 2 ++ install.sh | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/uninstall.sh b/bin/uninstall.sh index 95d0053..f16e017 100755 --- a/bin/uninstall.sh +++ b/bin/uninstall.sh @@ -67,6 +67,8 @@ scan_applications() { local -a app_dirs=( "/Applications" "$HOME/Applications" + "/Library/Input Methods" + "$HOME/Library/Input Methods" ) local vol_app_dir local nullglob_was_set=0 diff --git a/install.sh b/install.sh index a9c1c6f..b2408f3 100755 --- a/install.sh +++ b/install.sh @@ -493,8 +493,12 @@ install_files() { if needs_sudo; then log_admin "Admin access required for /usr/local/bin" fi - maybe_sudo cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole" - maybe_sudo chmod +x "$INSTALL_DIR/mole" + + # Atomic update: copy to temporary name first, then move + maybe_sudo cp "$SOURCE_DIR/mole" "$INSTALL_DIR/mole.new" + maybe_sudo chmod +x "$INSTALL_DIR/mole.new" + maybe_sudo mv -f "$INSTALL_DIR/mole.new" "$INSTALL_DIR/mole" + log_success "Installed mole to $INSTALL_DIR" fi else @@ -506,8 +510,9 @@ install_files() { if [[ "$source_dir_abs" == "$install_dir_abs" ]]; then log_success "mo alias already present" else - maybe_sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo" - maybe_sudo chmod +x "$INSTALL_DIR/mo" + maybe_sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo.new" + maybe_sudo chmod +x "$INSTALL_DIR/mo.new" + maybe_sudo mv -f "$INSTALL_DIR/mo.new" "$INSTALL_DIR/mo" log_success "Installed mo alias" fi fi