From e575ed53dcd0c0bf071eba88c952bb3e4b2fa210 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Tue, 7 Oct 2025 11:05:30 +0800 Subject: [PATCH] :bug: Optimize uninstallation of mole --- install.sh | 19 ++++++++++--------- mole | 11 +++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index e22d37b..986eaad 100755 --- a/install.sh +++ b/install.sh @@ -402,19 +402,20 @@ uninstall_mole() { # 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 + # Additional safety: never delete system critical paths (check first) 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") + /Library|/System|/bin|/sbin|/etc|/var|/opt|"$HOME"|"$HOME/Library"|\ + /usr/local/lib/*|/usr/local/share/*|/Library/*|/System/*) is_safe=0 ;; + *) + # Safe patterns: must be in user's home and end with 'mole' + if [[ "$CONFIG_DIR" == "$HOME/.config/mole" ]] || + [[ "$CONFIG_DIR" == "$HOME"/.*/mole ]]; then + is_safe=1 + fi + ;; esac # Ask before removing config directory diff --git a/mole b/mole index d0f26f1..a68fdf1 100755 --- a/mole +++ b/mole @@ -332,14 +332,17 @@ remove_mole() { done fi - # Clean up configuration and cache (both methods) - if [[ -d "$HOME/.config/mole" ]]; then - rm -rf "$HOME/.config/mole" 2>/dev/null && log_success "Removed configuration" - fi + # Clean up cache first (logs to config) if [[ -d "$HOME/.cache/mole" ]]; then rm -rf "$HOME/.cache/mole" 2>/dev/null && log_success "Removed cache" fi + # Clean up configuration last (contains logs) + if [[ -d "$HOME/.config/mole" ]]; then + log_success "Removed configuration" + rm -rf "$HOME/.config/mole" 2>/dev/null + fi + echo "" echo -e "${GREEN}✨ Mole has been removed successfully${NC}" echo ""