Compare commits

..

2 Commits

Author SHA1 Message Date
MickLesk
dbf3fa6f1d fix(tools.func): remove dangerous trap in create_temp_dir()
The EXIT/ERR/INT/TERM trap inside create_temp_dir() overwrites any
global traps and fires when the shell exits, not when the calling
function returns. Since the function is a utility that returns a path
via stdout, the trap fires immediately on function return and cannot
properly clean up the caller's temp dir. Callers already handle their
own cleanup via explicit rm -rf.
2026-03-19 20:26:38 +01:00
MickLesk
876d14721d refactor(tools.func): quality-of-life improvements
- setup_java(): replace dpkg -l with dpkg-query to avoid column truncation
  that caused version detection to fail and trigger unnecessary reinstalls
- get_cached_version(): return 1 when cache file not found (was always 0)
- setup_uv(): use trap RETURN instead of EXIT to avoid overwriting global
  traps and ensure cleanup runs on function return, not shell exit
- setup_docker(): declare DOCKER_CURRENT_VERSION and DOCKER_LATEST_VERSION
  as local to prevent global namespace pollution
2026-03-19 20:20:02 +01:00

View File

@@ -282,7 +282,7 @@ get_cached_version() {
cat "/var/cache/app-versions/${app}_version.txt"
return 0
fi
return 0
return 1
}
# ------------------------------------------------------------------------------
@@ -1100,8 +1100,9 @@ get_system_arch() {
# ------------------------------------------------------------------------------
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
# Callers should handle their own cleanup (rm -rf "$tmpdir")
# Do NOT set trap here — it would overwrite global traps and only fire
# when create_temp_dir() itself returns, not the calling function
echo "$tmp_dir"
}
@@ -5351,7 +5352,7 @@ function setup_java() {
"main"
fi
# Get currently installed version
# Get currently installed version (use dpkg-query to avoid column truncation)
local INSTALLED_VERSION=""
INSTALLED_VERSION=$(dpkg-query -W -f '${Package}\n' 2>/dev/null | grep -oP '^temurin-\K[0-9]+(?=-jdk$)' | head -n1 || echo "")
@@ -7832,8 +7833,8 @@ function setup_uv() {
local TMP_DIR=$(mktemp -d)
local CACHED_VERSION
# trap for TMP Cleanup
trap "rm -rf '$TMP_DIR'" EXIT
# trap for TMP Cleanup (RETURN instead of EXIT to avoid overwriting global traps)
trap "rm -rf '$TMP_DIR'" RETURN
CACHED_VERSION=$(get_cached_version "uv")
@@ -8103,6 +8104,8 @@ function setup_docker() {
local docker_installed=false
local portainer_installed=false
local USE_DOCKER_REPO="${USE_DOCKER_REPO:-false}"
local DOCKER_CURRENT_VERSION=""
local DOCKER_LATEST_VERSION=""
# Check if Docker is already installed
if command -v docker &>/dev/null; then