mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:04:42 +00:00
Fix macOS update detection timeout
This commit is contained in:
@@ -236,7 +236,7 @@ check_macos_update() {
|
|||||||
if [[ $(get_software_updates) == "Updates Available" ]]; then
|
if [[ $(get_software_updates) == "Updates Available" ]]; then
|
||||||
updates_available="true"
|
updates_available="true"
|
||||||
|
|
||||||
# Verify with softwareupdate -l (short timeout) to reduce false positives
|
# Verify with softwareupdate using --no-scan (fast) to reduce false positives
|
||||||
local sw_output=""
|
local sw_output=""
|
||||||
local sw_status=0
|
local sw_status=0
|
||||||
local spinner_started=false
|
local spinner_started=false
|
||||||
@@ -245,7 +245,9 @@ check_macos_update() {
|
|||||||
spinner_started=true
|
spinner_started=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! sw_output=$(run_with_timeout 5 softwareupdate -l 2> /dev/null); then
|
if sw_output=$(run_with_timeout 10 softwareupdate -l --no-scan 2> /dev/null); then
|
||||||
|
sw_status=0
|
||||||
|
else
|
||||||
sw_status=$?
|
sw_status=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -253,10 +255,9 @@ check_macos_update() {
|
|||||||
stop_inline_spinner
|
stop_inline_spinner
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If command failed, timed out, or returned empty, treat as no updates to avoid false positives
|
# Prefer avoiding false negatives: if the system indicates updates are pending,
|
||||||
if [[ $sw_status -ne 0 || -z "$sw_output" ]]; then
|
# only clear the flag when softwareupdate explicitly reports no updates.
|
||||||
updates_available="false"
|
if [[ $sw_status -eq 0 && -n "$sw_output" ]] && echo "$sw_output" | grep -q "No new software available"; then
|
||||||
elif echo "$sw_output" | grep -q "No new software available"; then
|
|
||||||
updates_available="false"
|
updates_available="false"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -186,25 +186,38 @@ EOF
|
|||||||
[[ "$output" == *"COUNT=0"* ]]
|
[[ "$output" == *"COUNT=0"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "check_macos_update warns when update available" {
|
@test "check_macos_update avoids slow softwareupdate scans" {
|
||||||
run bash --noprofile --norc <<'EOF'
|
run bash --noprofile --norc <<'EOF'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||||
source "$PROJECT_ROOT/lib/check/all.sh"
|
source "$PROJECT_ROOT/lib/check/all.sh"
|
||||||
|
|
||||||
softwareupdate() {
|
defaults() { echo "1"; }
|
||||||
echo "* Label: macOS 99"
|
|
||||||
return 0
|
run_with_timeout() {
|
||||||
|
shift
|
||||||
|
if [[ "${1:-}" == "softwareupdate" && "${2:-}" == "-l" && "${3:-}" == "--no-scan" ]]; then
|
||||||
|
cat <<'OUT'
|
||||||
|
Software Update Tool
|
||||||
|
|
||||||
|
Software Update found the following new or updated software:
|
||||||
|
* Label: macOS 99
|
||||||
|
OUT
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 124
|
||||||
}
|
}
|
||||||
|
|
||||||
start_inline_spinner(){ :; }
|
start_inline_spinner(){ :; }
|
||||||
stop_inline_spinner(){ :; }
|
stop_inline_spinner(){ :; }
|
||||||
|
|
||||||
check_macos_update
|
check_macos_update
|
||||||
|
echo "MACOS_UPDATE_AVAILABLE=$MACOS_UPDATE_AVAILABLE"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[[ "$output" == *"macOS"* ]]
|
[[ "$output" == *"Update available"* ]]
|
||||||
|
[[ "$output" == *"MACOS_UPDATE_AVAILABLE=true"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "run_with_timeout succeeds without GNU timeout" {
|
@test "run_with_timeout succeeds without GNU timeout" {
|
||||||
|
|||||||
Reference in New Issue
Block a user