tools.func: APT install and deb822 repo reliability (#15272)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
CanbiZ (MickLesk)
2026-06-21 23:10:27 +02:00
committed by GitHub
parent 6192225be7
commit 8b877f1c9f
+34 -12
View File
@@ -283,7 +283,7 @@ get_cached_version() {
cat "/var/cache/app-versions/${app}_version.txt"
return 0
fi
return 0
return 1
}
# ------------------------------------------------------------------------------
@@ -494,10 +494,10 @@ install_packages_with_retry() {
fi
fi
done
# If some packages installed, consider partial success
if [[ ${#failed[@]} -lt ${#packages[@]} ]]; then
if [[ ${#failed[@]} -gt 0 ]]; then
msg_warn "Partially installed. Failed packages: ${failed[*]}"
msg_error "Partial install — failed packages: ${failed[*]}"
return 100
fi
return 0
fi
@@ -1200,11 +1200,34 @@ get_system_arch() {
# ------------------------------------------------------------------------------
# Create temporary directory with automatic cleanup
# Appends to a shared list so existing EXIT traps are preserved.
# ------------------------------------------------------------------------------
_tools_temp_dirs=()
_tools_cleanup_temp_dirs() {
local d
for d in "${_tools_temp_dirs[@]}"; do
rm -rf "$d" 2>/dev/null || true
done
}
_tools_register_temp_cleanup() {
[[ "${_TOOLS_TEMP_TRAP_SET:-}" == "1" ]] && return 0
_TOOLS_TEMP_TRAP_SET=1
local existing
existing=$(trap -p EXIT 2>/dev/null | sed -n "s/^trap -- '\\(.*\\)' EXIT/\1/p" || true)
if [[ -n "$existing" && "$existing" != "_tools_cleanup_temp_dirs" ]]; then
trap "_tools_cleanup_temp_dirs; ${existing}" EXIT ERR INT TERM
else
trap _tools_cleanup_temp_dirs EXIT ERR INT TERM
fi
}
create_temp_dir() {
local tmp_dir=$(mktemp -d)
# Set trap to cleanup on EXIT, ERR, INT, TERM
trap "rm -rf '$tmp_dir'" EXIT ERR INT TERM
local tmp_dir
tmp_dir=$(mktemp -d) || return 1
_tools_temp_dirs+=("$tmp_dir")
_tools_register_temp_cleanup
echo "$tmp_dir"
}
@@ -2127,9 +2150,11 @@ setup_deb822_repo() {
[[ -n "$enabled" ]] && echo "Enabled: $enabled"
} >/etc/apt/sources.list.d/${name}.sources
$STD apt update || {
msg_warn "apt update failed after adding repository: ${name}"
}
if ! $STD apt update; then
msg_error "apt update failed after adding repository: ${name}"
msg_error "Hint: Verify suite '${suite}' and URI '${repo_url}' are valid for this distribution."
return 100
fi
}
# ------------------------------------------------------------------------------
@@ -8652,13 +8677,10 @@ setup_uv() {
local UV_BIN="/usr/local/bin/uv"
local UVX_BIN="/usr/local/bin/uvx"
local TMP_DIR=$(mktemp -d)
local CACHED_VERSION
# trap for TMP Cleanup
trap "rm -rf '$TMP_DIR'" EXIT
CACHED_VERSION=$(get_cached_version "uv")
# Architecture Detection
local ARCH=$(uname -m)
local OS_TYPE=""