mirror of
https://github.com/tw93/Mole.git
synced 2026-02-09 11:24:21 +00:00
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
This commit is contained in:
@@ -22,7 +22,7 @@ clean_empty_library_items() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 1. Clean top-level empty directories in Library
|
# 1. Clean top-level empty directories and files in Library
|
||||||
local -a empty_dirs=()
|
local -a empty_dirs=()
|
||||||
while IFS= read -r -d '' dir; do
|
while IFS= read -r -d '' dir; do
|
||||||
[[ -d "$dir" ]] && empty_dirs+=("$dir")
|
[[ -d "$dir" ]] && empty_dirs+=("$dir")
|
||||||
@@ -32,6 +32,24 @@ clean_empty_library_items() {
|
|||||||
safe_clean "${empty_dirs[@]}" "Empty Library folders"
|
safe_clean "${empty_dirs[@]}" "Empty Library folders"
|
||||||
fi
|
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
|
# 2. Clean empty subdirectories in Application Support and other key locations
|
||||||
# Iteratively remove empty directories until no more are found
|
# Iteratively remove empty directories until no more are found
|
||||||
local -a key_locations=(
|
local -a key_locations=(
|
||||||
|
|||||||
Reference in New Issue
Block a user