From a3539532aea6bef9db58b4c635eeb5210853d148 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Tue, 7 Oct 2025 10:54:53 +0800 Subject: [PATCH] :bug: Prevent deletion of system critical paths --- install.sh | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 06b8e8f..e22d37b 100755 --- a/install.sh +++ b/install.sh @@ -398,16 +398,43 @@ uninstall_mole() { log_success "Removed mo alias from $INSTALL_DIR" fi + # SAFETY CHECK: Verify config directory is safe to remove + # Only allow removal of mole-specific directories + local is_safe=0 + + # Safe patterns: must end with 'mole' or be in user's home .config + if [[ "$CONFIG_DIR" == "$HOME/.config/mole" ]] || + [[ "$CONFIG_DIR" == "$HOME"/.*/mole ]] || + [[ "$CONFIG_DIR" == */mole ]]; then + is_safe=1 + fi + + # Additional safety: never delete system critical paths + case "$CONFIG_DIR" in + /|/usr|/usr/local|/usr/local/bin|/usr/local/lib|/usr/local/share|\ + /Library|/System|/bin|/sbin|/etc|/var|/opt|"$HOME"|"$HOME/Library") + is_safe=0 + ;; + esac + # Ask before removing config directory if [[ -d "$CONFIG_DIR" ]]; then - echo "" - read -p "Remove configuration directory $CONFIG_DIR? (y/N): " -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - rm -rf "$CONFIG_DIR" - log_success "Removed configuration directory" + if [[ $is_safe -eq 0 ]]; then + log_warning "Config directory $CONFIG_DIR is not safe to auto-remove" + log_warning "Skipping automatic removal for safety" + echo "" + echo "Please manually review and remove mole-specific files from:" + echo " $CONFIG_DIR" else - log_info "Configuration directory preserved" + echo "" + read -p "Remove configuration directory $CONFIG_DIR? (y/N): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + rm -rf "$CONFIG_DIR" + log_success "Removed configuration directory" + else + log_info "Configuration directory preserved" + fi fi fi