From 7360f0a59ecc3bbfa24838fc3f2e4a8f04ccb29d Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 14 Jan 2026 09:49:47 +0800 Subject: [PATCH] feat: Implement empty file cleanup in ~/Library root (#234) - Add logic to remove 0-byte files in ~/Library (maxdepth 1) - Explicitly protect .localized files to preserve Finder localization - Respect global whitelist patterns --- lib/clean/user.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/clean/user.sh b/lib/clean/user.sh index 0308470..ae44ef8 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -22,7 +22,7 @@ clean_empty_library_items() { return 0 fi - # 1. Clean top-level empty directories in Library + # 1. Clean top-level empty directories and files in Library local -a empty_dirs=() while IFS= read -r -d '' dir; do [[ -d "$dir" ]] && empty_dirs+=("$dir") @@ -32,6 +32,24 @@ clean_empty_library_items() { safe_clean "${empty_dirs[@]}" "Empty Library folders" fi + # Clean empty files in Library root (skipping .localized and other sentinels) + local -a empty_files=() + while IFS= read -r -d '' file; do + [[ -f "$file" ]] || continue + # Protect .localized and potential system sentinels + if [[ "$(basename "$file")" == ".localized" ]]; then + continue + fi + if is_path_whitelisted "$file"; then + continue + fi + empty_files+=("$file") + done < <(find "$HOME/Library" -mindepth 1 -maxdepth 1 -type f -empty -print0 2> /dev/null) + + if [[ ${#empty_files[@]} -gt 0 ]]; then + safe_clean "${empty_files[@]}" "Empty Library files" + fi + # 2. Clean empty subdirectories in Application Support and other key locations # Iteratively remove empty directories until no more are found local -a key_locations=(