mirror of
https://github.com/tw93/Mole.git
synced 2026-02-06 21:15:37 +00:00
fix: resolve syntax error in size calculation (Issue #203)
- Add numeric validation for size variables in safe_clean() - Fix get_path_size_kb() to handle non-numeric du output - Display custom whitelist patterns in dry-run output (Issue #206)
This commit is contained in:
@@ -94,6 +94,12 @@ safe_remove() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Dry-run mode: log but don't delete
|
||||
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||
debug_log "[DRY RUN] Would remove: $path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
debug_log "Removing: $path"
|
||||
|
||||
# Perform the deletion
|
||||
@@ -139,6 +145,12 @@ safe_sudo_remove() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Dry-run mode: log but don't delete
|
||||
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||
debug_log "[DRY RUN] Would remove (sudo): $path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
debug_log "Removing (sudo): $path"
|
||||
|
||||
# Perform the deletion
|
||||
@@ -257,8 +269,14 @@ get_path_size_kb() {
|
||||
# Use || echo 0 to ensure failure in du (e.g. permission error) doesn't exit script under set -e
|
||||
# Pipefail would normally cause the pipeline to fail if du fails, but || handle catches it.
|
||||
local size
|
||||
size=$(command du -sk "$path" 2> /dev/null | awk '{print $1}' || echo "0")
|
||||
echo "${size:-0}"
|
||||
size=$(command du -sk "$path" 2> /dev/null | awk '{print $1}' || true)
|
||||
|
||||
# Ensure size is a valid number (fix for non-numeric du output)
|
||||
if [[ "$size" =~ ^[0-9]+$ ]]; then
|
||||
echo "$size"
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Calculate total size for multiple paths
|
||||
|
||||
Reference in New Issue
Block a user