diff --git a/lib/clean/system.sh b/lib/clean/system.sh index bb95e9c..27d6ab0 100644 --- a/lib/clean/system.sh +++ b/lib/clean/system.sh @@ -267,40 +267,21 @@ tm_is_running() { grep -qE '(^|[[:space:]])("Running"|Running)[[:space:]]*=[[:space:]]*1([[:space:]]*;|$)' <<< "$st" } -# Returns 0 if snapshot mounts exist under local snapshot paths -# Returns 1 if none found -# Returns 2 if mount state cannot be determined -tm_snapshots_mounted() { - local m - if ! m="$(run_with_timeout 3 mount 2> /dev/null)"; then - return 2 - fi - # Match modern and legacy local-snapshot browse mounts: - # - /Volumes/com.apple.TimeMachine.localsnapshots/... (APFS) - # - /.TimeMachine (APFS) - # - /Volumes/MobileBackups (HFS+, legacy) - grep -qE '[[:space:]]on[[:space:]](/\.TimeMachine(/|[[:space:]])|/Volumes/com\.apple\.TimeMachine\.localsnapshots(/|[[:space:]])|/Volumes/MobileBackups(/|[[:space:]]))' <<< "$m" -} - # Local APFS snapshots (keep the most recent). clean_local_snapshots() { if ! command -v tmutil > /dev/null 2>&1; then return 0 fi - local rc_running rc_mounted - rc_running=0 + local rc_running=0 tm_is_running || rc_running=$? - rc_mounted=0 - tm_snapshots_mounted || rc_mounted=$? - - if [[ $rc_running -eq 2 || $rc_mounted -eq 2 ]]; then + if [[ $rc_running -eq 2 ]]; then echo -e " ${YELLOW}!${NC} Could not determine Time Machine status; skipping snapshot cleanup" return 0 fi - if [[ $rc_running -eq 0 || $rc_mounted -eq 0 ]]; then + if [[ $rc_running -eq 0 ]]; then echo -e " ${YELLOW}!${NC} Time Machine is active; skipping snapshot cleanup" return 0 fi diff --git a/tests/clean_system_maintenance.bats b/tests/clean_system_maintenance.bats index a594b0d..7be620b 100644 --- a/tests/clean_system_maintenance.bats +++ b/tests/clean_system_maintenance.bats @@ -126,7 +126,6 @@ tmutil() { start_section_spinner(){ :; } stop_section_spinner(){ :; } tm_is_running(){ return 1; } -tm_snapshots_mounted(){ return 1; } DRY_RUN="false" clean_local_snapshots @@ -157,7 +156,6 @@ start_section_spinner(){ :; } stop_section_spinner(){ :; } note_activity(){ :; } tm_is_running(){ return 1; } -tm_snapshots_mounted(){ return 1; } DRY_RUN="true" clean_local_snapshots @@ -193,7 +191,6 @@ start_section_spinner(){ :; } stop_section_spinner(){ :; } note_activity(){ :; } tm_is_running(){ return 1; } -tm_snapshots_mounted(){ return 1; } unset -f read_key