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

🐛 Optimize uninstallation of mole

This commit is contained in:
Tw93
2025-10-07 11:05:30 +08:00
parent a6fe681ad5
commit e575ed53dc
2 changed files with 17 additions and 13 deletions

View File

@@ -402,19 +402,20 @@ uninstall_mole() {
# Only allow removal of mole-specific directories # Only allow removal of mole-specific directories
local is_safe=0 local is_safe=0
# Safe patterns: must end with 'mole' or be in user's home .config # Additional safety: never delete system critical paths (check first)
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 case "$CONFIG_DIR" in
/|/usr|/usr/local|/usr/local/bin|/usr/local/lib|/usr/local/share|\ /|/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 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 esac
# Ask before removing config directory # Ask before removing config directory

11
mole
View File

@@ -332,14 +332,17 @@ remove_mole() {
done done
fi fi
# Clean up configuration and cache (both methods) # Clean up cache first (logs to config)
if [[ -d "$HOME/.config/mole" ]]; then
rm -rf "$HOME/.config/mole" 2>/dev/null && log_success "Removed configuration"
fi
if [[ -d "$HOME/.cache/mole" ]]; then if [[ -d "$HOME/.cache/mole" ]]; then
rm -rf "$HOME/.cache/mole" 2>/dev/null && log_success "Removed cache" rm -rf "$HOME/.cache/mole" 2>/dev/null && log_success "Removed cache"
fi 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 ""
echo -e "${GREEN}✨ Mole has been removed successfully${NC}" echo -e "${GREEN}✨ Mole has been removed successfully${NC}"
echo "" echo ""