diff --git a/bin/clean.sh b/bin/clean.sh index b76e392..a72c891 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -122,7 +122,7 @@ whitelist_skipped_count=0 # shellcheck disable=SC2329 note_activity() { - if [[ $TRACK_SECTION -eq 1 ]]; then + if [[ "${TRACK_SECTION:-0}" == "1" ]]; then SECTION_ACTIVITY=1 fi } @@ -183,7 +183,7 @@ start_section() { end_section() { stop_section_spinner - if [[ $TRACK_SECTION -eq 1 && $SECTION_ACTIVITY -eq 0 ]]; then + if [[ "${TRACK_SECTION:-0}" == "1" && "${SECTION_ACTIVITY:-0}" == "0" ]]; then echo -e " ${GREEN}${ICON_SUCCESS}${NC} Nothing to clean" fi TRACK_SECTION=0 @@ -275,7 +275,7 @@ safe_clean() { return 0 fi - if [[ $TRACK_SECTION -eq 1 && $SECTION_ACTIVITY -eq 0 ]]; then + if [[ "${TRACK_SECTION:-0}" == "1" && "${SECTION_ACTIVITY:-0}" == "0" ]]; then stop_section_spinner fi diff --git a/lib/clean/user.sh b/lib/clean/user.sh index f4b810f..e16ff10 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -131,7 +131,14 @@ clean_mail_downloads() { if [[ -d "$target_path" ]]; then local dir_size_kb=0 dir_size_kb=$(get_path_size_kb "$target_path") - if [[ $dir_size_kb -lt ${MOLE_MAIL_DOWNLOADS_MIN_KB:-5120} ]]; then + if ! [[ "$dir_size_kb" =~ ^[0-9]+$ ]]; then + dir_size_kb=0 + fi + local min_kb="${MOLE_MAIL_DOWNLOADS_MIN_KB:-5120}" + if ! [[ "$min_kb" =~ ^[0-9]+$ ]]; then + min_kb=5120 + fi + if [[ "$dir_size_kb" -lt "$min_kb" ]]; then continue fi while IFS= read -r -d '' file_path; do diff --git a/lib/core/base.sh b/lib/core/base.sh index eda3757..5bfbfbf 100644 --- a/lib/core/base.sh +++ b/lib/core/base.sh @@ -569,7 +569,7 @@ start_section() { # End a section # Shows "Nothing to tidy" if no activity was recorded end_section() { - if [[ $TRACK_SECTION -eq 1 && $SECTION_ACTIVITY -eq 0 ]]; then + if [[ "${TRACK_SECTION:-0}" == "1" && "${SECTION_ACTIVITY:-0}" == "0" ]]; then echo -e " ${GREEN}${ICON_SUCCESS}${NC} Nothing to tidy" fi TRACK_SECTION=0 @@ -577,7 +577,7 @@ end_section() { # Mark activity in current section note_activity() { - if [[ $TRACK_SECTION -eq 1 ]]; then + if [[ "${TRACK_SECTION:-0}" == "1" ]]; then SECTION_ACTIVITY=1 fi } diff --git a/lib/core/file_ops.sh b/lib/core/file_ops.sh index af6d82f..23a9463 100644 --- a/lib/core/file_ops.sh +++ b/lib/core/file_ops.sh @@ -269,7 +269,7 @@ 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}' || true) + size=$(command du -sk "$path" 2> /dev/null | awk 'NR==1 {print $1; exit}' || true) # Ensure size is a valid number (fix for non-numeric du output) if [[ "$size" =~ ^[0-9]+$ ]]; then