Skip to content

Commit adcd980

Browse files
committed
fix(update): keep sudo session alive during installer run
Start sudo keepalive after authorization and clean it up on all failure/success paths to avoid repeated password prompts and overlapping update UI output. Closes #514.
1 parent 172742b commit adcd980

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

mole

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,13 @@ update_mole() {
249249
local force_update="${1:-false}"
250250
local nightly_update="${2:-false}"
251251
local update_interrupted=false
252-
trap 'update_interrupted=true; echo ""; exit 130' INT TERM
252+
local sudo_keepalive_pid=""
253+
254+
# Cleanup function for sudo keepalive
255+
_update_cleanup() {
256+
[[ -n "$sudo_keepalive_pid" ]] && _stop_sudo_keepalive "$sudo_keepalive_pid" || true
257+
}
258+
trap '_update_cleanup; update_interrupted=true; echo ""; exit 130' INT TERM
253259

254260
if is_homebrew_install; then
255261
if [[ "$nightly_update" == "true" ]]; then
@@ -360,6 +366,8 @@ update_mole() {
360366
rm -f "$tmp_installer"
361367
exit 1
362368
fi
369+
# Start sudo keepalive to prevent cache expiration during install
370+
sudo_keepalive_pid=$(_start_sudo_keepalive)
363371
fi
364372

365373
if [[ -t 1 ]]; then
@@ -411,6 +419,7 @@ update_mole() {
411419
else
412420
if [[ -t 1 ]]; then stop_inline_spinner; fi
413421
rm -f "$tmp_installer"
422+
_update_cleanup
414423
log_error "Nightly update failed"
415424
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
416425
exit 1
@@ -421,6 +430,7 @@ update_mole() {
421430
else
422431
if [[ -t 1 ]]; then stop_inline_spinner; fi
423432
rm -f "$tmp_installer"
433+
_update_cleanup
424434
log_error "Update failed"
425435
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
426436
exit 1
@@ -434,6 +444,7 @@ update_mole() {
434444
else
435445
if [[ -t 1 ]]; then stop_inline_spinner; fi
436446
rm -f "$tmp_installer"
447+
_update_cleanup
437448
log_error "Update failed"
438449
echo "$install_output" | tail -10 >&2 # Show last 10 lines of error
439450
exit 1
@@ -443,6 +454,10 @@ update_mole() {
443454

444455
rm -f "$tmp_installer"
445456
rm -f "$HOME/.cache/mole/update_message"
457+
458+
# Cleanup and reset trap
459+
_update_cleanup
460+
trap - INT TERM
446461
}
447462

448463
# Remove flow (Homebrew + manual + config/cache).

0 commit comments

Comments
 (0)