1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 07:15:07 +00:00

refactor: reuse sudo cache checks in clean dry-run tests

This commit is contained in:
tw93
2026-02-25 10:32:12 +08:00
parent ee1f2bd372
commit 5241b59ea9
2 changed files with 49 additions and 28 deletions

View File

@@ -137,6 +137,11 @@ note_activity() {
fi
}
# shellcheck disable=SC2329
has_cached_sudo() {
sudo -n true 2> /dev/null
}
CLEANUP_DONE=false
# shellcheck disable=SC2329
cleanup() {
@@ -733,7 +738,7 @@ start_cleanup() {
EOF
# Preview system section when sudo is already cached (no password prompt).
if sudo -n true 2> /dev/null; then
if has_cached_sudo; then
SYSTEM_CLEAN=true
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access available, system preview included"
echo ""
@@ -746,7 +751,7 @@ EOF
fi
if [[ -t 0 ]]; then
if sudo -n true 2> /dev/null; then
if has_cached_sudo; then
SYSTEM_CLEAN=true
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access already available"
echo ""
@@ -786,7 +791,7 @@ EOF
else
echo ""
echo "Running in non-interactive mode"
if sudo -n true 2> /dev/null; then
if has_cached_sudo; then
SYSTEM_CLEAN=true
echo " ${ICON_LIST} System-level cleanup enabled, sudo session active"
else