1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 18:30:08 +00:00

fix(clean): guard empty Xcode DeviceSupport arrays

This commit is contained in:
tw93
2026-03-07 23:07:38 +08:00
parent b12308f3ad
commit 50efe51565
2 changed files with 55 additions and 35 deletions

View File

@@ -359,6 +359,7 @@ clean_xcode_device_support() {
version_dirs+=("$entry") version_dirs+=("$entry")
done < <(command find "$ds_dir" -mindepth 1 -maxdepth 1 -print0 2> /dev/null) done < <(command find "$ds_dir" -mindepth 1 -maxdepth 1 -print0 2> /dev/null)
if [[ ${#version_dirs[@]} -gt 0 ]]; then
# Sort by modification time (most recent first) # Sort by modification time (most recent first)
local -a sorted_dirs=() local -a sorted_dirs=()
while IFS= read -r line; do while IFS= read -r line; do
@@ -403,6 +404,7 @@ clean_xcode_device_support() {
fi fi
fi fi
fi fi
fi
# Clean caches/logs inside kept versions # Clean caches/logs inside kept versions
safe_clean "$ds_dir"/*/Symbols/System/Library/Caches/* "$display_name symbol cache" safe_clean "$ds_dir"/*/Symbols/System/Library/Caches/* "$display_name symbol cache"

View File

@@ -136,6 +136,24 @@ EOF
[[ "$output" != *"NDK versions"* ]] [[ "$output" != *"NDK versions"* ]]
} }
@test "clean_xcode_device_support handles empty directories under nounset" {
local ds_dir="$HOME/EmptyDeviceSupport"
mkdir -p "$ds_dir"
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/dev.sh"
note_activity() { :; }
safe_clean() { :; }
clean_xcode_device_support "$HOME/EmptyDeviceSupport" "iOS DeviceSupport"
echo "survived"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"survived"* ]]
}
@test "clean_xcode_documentation_cache keeps newest DeveloperDocumentation index" { @test "clean_xcode_documentation_cache keeps newest DeveloperDocumentation index" {
local doc_root="$HOME/DocumentationCache" local doc_root="$HOME/DocumentationCache"
mkdir -p "$doc_root" mkdir -p "$doc_root"