1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 01:54:16 +00:00

Safety reinforcement

This commit is contained in:
Tw93
2025-12-03 20:31:17 +08:00
parent 73f5cc8059
commit 2c0f602ebd
4 changed files with 8 additions and 6 deletions

View File

@@ -273,7 +273,7 @@ safe_clean() {
local size local size
size=$(get_path_size_kb "$path") size=$(get_path_size_kb "$path")
local count local count
count=$(find "$path" -type f 2> /dev/null | wc -l | tr -d ' ') count=$(find -- "$path" -type f 2> /dev/null | wc -l | tr -d ' ')
# Use index + PID for unique filename # Use index + PID for unique filename
local tmp_file="$temp_dir/result_${idx}.$$" local tmp_file="$temp_dir/result_${idx}.$$"
echo "$size $count" > "$tmp_file" echo "$size $count" > "$tmp_file"
@@ -332,7 +332,7 @@ safe_clean() {
local size_bytes local size_bytes
size_bytes=$(get_path_size_kb "$path") size_bytes=$(get_path_size_kb "$path")
local count local count
count=$(find "$path" -type f 2> /dev/null | wc -l | tr -d ' ') count=$(find -- "$path" -type f 2> /dev/null | wc -l | tr -d ' ')
if [[ "$count" -gt 0 && "$size_bytes" -gt 0 ]]; then if [[ "$count" -gt 0 && "$size_bytes" -gt 0 ]]; then
if [[ "$DRY_RUN" != "true" ]]; then if [[ "$DRY_RUN" != "true" ]]; then

View File

@@ -34,6 +34,8 @@ clean_orphaned_casks() {
else else
# Rebuild cache: query all installed casks and extract app names # Rebuild cache: query all installed casks and extract app names
mkdir -p "$cache_dir" mkdir -p "$cache_dir"
# Remove stale cache if it exists but has permission issues
rm -f "$cask_cache" 2> /dev/null || true
true > "$cask_cache" true > "$cask_cache"
while IFS= read -r cask; do while IFS= read -r cask; do

View File

@@ -241,7 +241,7 @@ safe_find_delete() {
fi fi
# Execute find with safety limits # Execute find with safety limits
find "$base_dir" \ find -- "$base_dir" \
-maxdepth 3 \ -maxdepth 3 \
-name "$pattern" \ -name "$pattern" \
-type "$type_filter" \ -type "$type_filter" \
@@ -277,7 +277,7 @@ safe_sudo_find_delete() {
fi fi
# Execute find with safety limits # Execute find with safety limits
sudo find "$base_dir" \ sudo find -- "$base_dir" \
-maxdepth 3 \ -maxdepth 3 \
-name "$pattern" \ -name "$pattern" \
-type "$type_filter" \ -type "$type_filter" \
@@ -1150,7 +1150,7 @@ clean_tool_cache() {
get_path_size_kb() { get_path_size_kb() {
local path="$1" local path="$1"
local result local result
result=$(du -sk "$path" 2> /dev/null | awk '{print $1}') result=$(du -sk -- "$path" 2> /dev/null | awk '{print $1}')
echo "${result:-0}" echo "${result:-0}"
} }

2
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/core/common.sh" source "$SCRIPT_DIR/lib/core/common.sh"
# Version info # Version info
VERSION="1.11.17" VERSION="1.11.18"
MOLE_TAGLINE="can dig deep to clean your Mac." MOLE_TAGLINE="can dig deep to clean your Mac."
# Check if Touch ID is already configured # Check if Touch ID is already configured