mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 12:21:11 +00:00
fix: remove unsafe file cleanup in Library root and fix tests
- lib/clean: remove empty file cleanup in ~/Library to protect potential sentinel files - tests: fix unbound variable error in clean_user_core.bats by initializing WHITELIST_PATTERNS
This commit is contained in:
@@ -32,23 +32,7 @@ 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
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ set -euo pipefail
|
|||||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||||
source "$PROJECT_ROOT/lib/clean/user.sh"
|
source "$PROJECT_ROOT/lib/clean/user.sh"
|
||||||
safe_clean() { echo "$2"; }
|
safe_clean() { echo "$2"; }
|
||||||
|
WHITELIST_PATTERNS=()
|
||||||
mkdir -p "$HOME/Library/EmptyDir"
|
mkdir -p "$HOME/Library/EmptyDir"
|
||||||
touch "$HOME/Library/empty.txt"
|
touch "$HOME/Library/empty.txt"
|
||||||
clean_empty_library_items
|
clean_empty_library_items
|
||||||
|
|||||||
Reference in New Issue
Block a user