1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-12 22:10:14 +00:00

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
This commit is contained in:
Tw93
2026-01-04 23:17:42 +08:00
parent 3906c020fe
commit 8a0b98525c
2 changed files with 11 additions and 4 deletions

View File

@@ -67,6 +67,8 @@ scan_applications() {
local -a app_dirs=( local -a app_dirs=(
"/Applications" "/Applications"
"$HOME/Applications" "$HOME/Applications"
"/Library/Input Methods"
"$HOME/Library/Input Methods"
) )
local vol_app_dir local vol_app_dir
local nullglob_was_set=0 local nullglob_was_set=0

View File

@@ -493,8 +493,12 @@ install_files() {
if needs_sudo; then if needs_sudo; then
log_admin "Admin access required for /usr/local/bin" log_admin "Admin access required for /usr/local/bin"
fi 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" log_success "Installed mole to $INSTALL_DIR"
fi fi
else else
@@ -506,8 +510,9 @@ install_files() {
if [[ "$source_dir_abs" == "$install_dir_abs" ]]; then if [[ "$source_dir_abs" == "$install_dir_abs" ]]; then
log_success "mo alias already present" log_success "mo alias already present"
else else
maybe_sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo" maybe_sudo cp "$SOURCE_DIR/mo" "$INSTALL_DIR/mo.new"
maybe_sudo chmod +x "$INSTALL_DIR/mo" maybe_sudo chmod +x "$INSTALL_DIR/mo.new"
maybe_sudo mv -f "$INSTALL_DIR/mo.new" "$INSTALL_DIR/mo"
log_success "Installed mo alias" log_success "Installed mo alias"
fi fi
fi fi