mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 23:05:08 +00:00
feat(clean): expand conservative cache cleanup coverage
- add conservative support/app/system cache targets\n- fix dry-run + success logging behavior for memory exception cleanup\n- add regression tests for new cleanup paths and safeguards\n\nRefs #477
This commit is contained in:
@@ -13,12 +13,15 @@ clean_xcode_tools() {
|
||||
safe_clean ~/Library/Caches/com.apple.dt.Xcode/* "Xcode cache"
|
||||
safe_clean ~/Library/Developer/Xcode/iOS\ Device\ Logs/* "iOS device logs"
|
||||
safe_clean ~/Library/Developer/Xcode/watchOS\ Device\ Logs/* "watchOS device logs"
|
||||
safe_clean ~/Library/Logs/CoreSimulator/* "CoreSimulator logs"
|
||||
safe_clean ~/Library/Developer/Xcode/Products/* "Xcode build products"
|
||||
if [[ "$xcode_running" == "false" ]]; then
|
||||
safe_clean ~/Library/Developer/Xcode/DerivedData/* "Xcode derived data"
|
||||
safe_clean ~/Library/Developer/Xcode/Archives/* "Xcode archives"
|
||||
safe_clean ~/Library/Developer/Xcode/DocumentationCache/* "Xcode documentation cache"
|
||||
safe_clean ~/Library/Developer/Xcode/DocumentationIndex/* "Xcode documentation index"
|
||||
else
|
||||
echo -e " ${GRAY}${ICON_WARNING}${NC} Xcode is running, skipping DerivedData and Archives cleanup"
|
||||
echo -e " ${GRAY}${ICON_WARNING}${NC} Xcode is running, skipping DerivedData/Archives/Documentation cleanup"
|
||||
fi
|
||||
}
|
||||
# Code editors.
|
||||
@@ -43,6 +46,12 @@ clean_communication_apps() {
|
||||
safe_clean ~/Library/Caches/com.tencent.meeting/* "Tencent Meeting cache"
|
||||
safe_clean ~/Library/Caches/com.tencent.WeWorkMac/* "WeCom cache"
|
||||
safe_clean ~/Library/Caches/com.feishu.*/* "Feishu cache"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/Cache/* "Microsoft Teams legacy cache"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/Application\ Cache/* "Microsoft Teams legacy application cache"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/Code\ Cache/* "Microsoft Teams legacy code cache"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/GPUCache/* "Microsoft Teams legacy GPU cache"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/logs/* "Microsoft Teams legacy logs"
|
||||
safe_clean ~/Library/Application\ Support/Microsoft/Teams/tmp/* "Microsoft Teams legacy temp files"
|
||||
}
|
||||
# DingTalk.
|
||||
clean_dingtalk() {
|
||||
@@ -64,6 +73,7 @@ clean_design_tools() {
|
||||
safe_clean ~/Library/Caches/Adobe/* "Adobe cache"
|
||||
safe_clean ~/Library/Caches/com.adobe.*/* "Adobe app caches"
|
||||
safe_clean ~/Library/Caches/com.figma.Desktop/* "Figma cache"
|
||||
safe_clean ~/Library/Application\ Support/Adobe/Common/Media\ Cache\ Files/* "Adobe media cache files"
|
||||
# Raycast cache is protected (clipboard history, images).
|
||||
}
|
||||
# Video editing tools.
|
||||
@@ -150,12 +160,25 @@ clean_download_managers() {
|
||||
clean_gaming_platforms() {
|
||||
safe_clean ~/Library/Caches/com.valvesoftware.steam/* "Steam cache"
|
||||
safe_clean ~/Library/Application\ Support/Steam/htmlcache/* "Steam web cache"
|
||||
safe_clean ~/Library/Application\ Support/Steam/appcache/* "Steam app cache"
|
||||
safe_clean ~/Library/Application\ Support/Steam/depotcache/* "Steam depot cache"
|
||||
safe_clean ~/Library/Application\ Support/Steam/steamapps/shadercache/* "Steam shader cache"
|
||||
safe_clean ~/Library/Application\ Support/Steam/logs/* "Steam logs"
|
||||
safe_clean ~/Library/Caches/com.epicgames.EpicGamesLauncher/* "Epic Games cache"
|
||||
safe_clean ~/Library/Caches/com.blizzard.Battle.net/* "Battle.net cache"
|
||||
safe_clean ~/Library/Application\ Support/Battle.net/Cache/* "Battle.net app cache"
|
||||
safe_clean ~/Library/Caches/com.ea.*/* "EA Origin cache"
|
||||
safe_clean ~/Library/Caches/com.gog.galaxy/* "GOG Galaxy cache"
|
||||
safe_clean ~/Library/Caches/com.riotgames.*/* "Riot Games cache"
|
||||
safe_clean ~/Library/Application\ Support/minecraft/logs/* "Minecraft logs"
|
||||
safe_clean ~/Library/Application\ Support/minecraft/crash-reports/* "Minecraft crash reports"
|
||||
safe_clean ~/Library/Application\ Support/minecraft/webcache/* "Minecraft web cache"
|
||||
safe_clean ~/Library/Application\ Support/minecraft/webcache2/* "Minecraft web cache 2"
|
||||
safe_clean ~/.lunarclient/game-cache/* "Lunar Client game cache"
|
||||
safe_clean ~/.lunarclient/launcher-cache/* "Lunar Client launcher cache"
|
||||
safe_clean ~/.lunarclient/logs/* "Lunar Client logs"
|
||||
safe_clean ~/.lunarclient/offline/*/logs/* "Lunar Client offline logs"
|
||||
safe_clean ~/.lunarclient/offline/files/*/logs/* "Lunar Client offline file logs"
|
||||
}
|
||||
# Translation/dictionary apps.
|
||||
clean_translation_apps() {
|
||||
@@ -185,6 +208,8 @@ clean_shell_utils() {
|
||||
safe_clean ~/.lesshst "less history"
|
||||
safe_clean ~/.viminfo.tmp "Vim temporary files"
|
||||
safe_clean ~/.wget-hsts "wget HSTS cache"
|
||||
safe_clean ~/.cacher/logs/* "Cacher logs"
|
||||
safe_clean ~/.kite/logs/* "Kite logs"
|
||||
}
|
||||
# Input methods and system utilities.
|
||||
clean_system_utils() {
|
||||
|
||||
@@ -47,6 +47,25 @@ clean_deep_system() {
|
||||
fi
|
||||
stop_section_spinner
|
||||
log_success "System logs"
|
||||
start_section_spinner "Cleaning third-party system logs..."
|
||||
local -a third_party_log_dirs=(
|
||||
"/Library/Logs/Adobe"
|
||||
"/Library/Logs/CreativeCloud"
|
||||
)
|
||||
local third_party_logs_cleaned=0
|
||||
local third_party_log_dir=""
|
||||
for third_party_log_dir in "${third_party_log_dirs[@]}"; do
|
||||
if sudo test -d "$third_party_log_dir" 2> /dev/null; then
|
||||
safe_sudo_find_delete "$third_party_log_dir" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||
third_party_logs_cleaned=1
|
||||
fi
|
||||
done
|
||||
if sudo find "/Library/Logs" -maxdepth 1 -type f -name "adobegc.log" -mtime "+$MOLE_LOG_AGE_DAYS" -print -quit 2> /dev/null | grep -q .; then
|
||||
safe_sudo_remove "/Library/Logs/adobegc.log" || true
|
||||
third_party_logs_cleaned=1
|
||||
fi
|
||||
stop_section_spinner
|
||||
[[ $third_party_logs_cleaned -eq 1 ]] && log_success "Third-party system logs"
|
||||
start_section_spinner "Scanning system library updates..."
|
||||
if [[ -d "/Library/Updates" && ! -L "/Library/Updates" ]]; then
|
||||
local updates_cleaned=0
|
||||
@@ -143,6 +162,7 @@ clean_deep_system() {
|
||||
log_success "Power logs"
|
||||
start_section_spinner "Cleaning memory exception reports..."
|
||||
local mem_reports_dir="/private/var/db/reportmemoryexception/MemoryLimitViolations"
|
||||
local mem_cleaned=0
|
||||
if sudo test -d "$mem_reports_dir" 2> /dev/null; then
|
||||
# Count and size old files before deletion
|
||||
local file_count=0
|
||||
@@ -155,10 +175,12 @@ clean_deep_system() {
|
||||
done < <(sudo find "$mem_reports_dir" -type f -mtime +30 -print0 2> /dev/null || true)
|
||||
|
||||
if [[ "$file_count" -gt 0 ]]; then
|
||||
if [[ "${MOLE_DRY_RUN:-0}" != "1" ]]; then
|
||||
safe_sudo_find_delete "$mem_reports_dir" "*" "30" "f" || true
|
||||
if [[ "${DRY_RUN:-false}" != "true" ]]; then
|
||||
if safe_sudo_find_delete "$mem_reports_dir" "*" "30" "f"; then
|
||||
mem_cleaned=1
|
||||
fi
|
||||
# Log summary to operations.log
|
||||
if oplog_enabled && [[ "$total_size_kb" -gt 0 ]]; then
|
||||
if [[ $mem_cleaned -eq 1 ]] && oplog_enabled && [[ "$total_size_kb" -gt 0 ]]; then
|
||||
local size_human
|
||||
size_human=$(bytes_to_human "$((total_size_kb * 1024))")
|
||||
log_operation "clean" "REMOVED" "$mem_reports_dir" "$file_count files, $size_human"
|
||||
@@ -169,7 +191,10 @@ clean_deep_system() {
|
||||
fi
|
||||
fi
|
||||
stop_section_spinner
|
||||
log_success "Memory exception reports"
|
||||
if [[ $mem_cleaned -eq 1 ]]; then
|
||||
log_success "Memory exception reports"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
# Incomplete Time Machine backups.
|
||||
clean_time_machine_failed_backups() {
|
||||
|
||||
@@ -394,6 +394,33 @@ clean_finder_metadata() {
|
||||
fi
|
||||
clean_ds_store_tree "$HOME" "Home directory, .DS_Store"
|
||||
}
|
||||
|
||||
# Conservative cleanup for support caches not covered by generic rules.
|
||||
clean_support_app_data() {
|
||||
local support_age_days="${MOLE_SUPPORT_CACHE_AGE_DAYS:-30}"
|
||||
[[ "$support_age_days" =~ ^[0-9]+$ ]] || support_age_days=30
|
||||
|
||||
local crash_reporter_dir="$HOME/Library/Application Support/CrashReporter"
|
||||
if [[ -d "$crash_reporter_dir" && ! -L "$crash_reporter_dir" ]]; then
|
||||
safe_find_delete "$crash_reporter_dir" "*" "$support_age_days" "f" || true
|
||||
fi
|
||||
|
||||
# Keep recent wallpaper assets to avoid large re-downloads.
|
||||
local idle_assets_dir="$HOME/Library/Application Support/com.apple.idleassetsd"
|
||||
if [[ -d "$idle_assets_dir" && ! -L "$idle_assets_dir" ]]; then
|
||||
safe_find_delete "$idle_assets_dir" "*" "$support_age_days" "f" || true
|
||||
fi
|
||||
|
||||
# Do not touch Messages attachments, only preview/sticker caches.
|
||||
if pgrep -x "Messages" > /dev/null 2>&1; then
|
||||
echo -e " ${GRAY}${ICON_WARNING}${NC} Messages is running · preview cache cleanup skipped"
|
||||
return 0
|
||||
fi
|
||||
safe_clean ~/Library/Messages/StickerCache/* "Messages sticker cache"
|
||||
safe_clean ~/Library/Messages/Caches/Previews/Attachments/* "Messages preview attachment cache"
|
||||
safe_clean ~/Library/Messages/Caches/Previews/StickerCache/* "Messages preview sticker cache"
|
||||
}
|
||||
|
||||
# App caches (merged: macOS system caches + Sandboxed apps).
|
||||
clean_app_caches() {
|
||||
# macOS system caches (merged from clean_macos_system_caches)
|
||||
@@ -413,6 +440,7 @@ clean_app_caches() {
|
||||
safe_clean ~/Library/Suggestions/* "Siri suggestions cache" || true
|
||||
safe_clean ~/Library/Calendars/Calendar\ Cache "Calendar cache" || true
|
||||
safe_clean ~/Library/Application\ Support/AddressBook/Sources/*/Photos.cache "Address Book photo cache" || true
|
||||
clean_support_app_data
|
||||
|
||||
# Sandboxed app caches
|
||||
stop_section_spinner
|
||||
|
||||
Reference in New Issue
Block a user