mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-03-03 14:55:54 +00:00
Flush terminal input and make repo cache global
Restore and sanitize terminal state before prompting by draining stale input from /dev/tty (dd iflag=nonblock) and adding a short sleep, then perform timed reads from /dev/tty in misc/build.func and misc/error_handler.func. Also make _REPO_CACHE a global associative array (declare -gA) with fallbacks in misc/tools.func so the cache survives when tools.func is sourced inside a function scope.
This commit is contained in:
@@ -4391,12 +4391,16 @@ EOF'
|
||||
echo ""
|
||||
echo -en "${YW}Select option [1-${max_option}] (default: 1, auto-remove in 60s): ${CL}"
|
||||
|
||||
# Ensure terminal is sane before reading input (lxc-attach|tee may corrupt tty state)
|
||||
# Restore terminal state after lxc-attach|tee pipeline
|
||||
stty sane 2>/dev/null || true
|
||||
# Drain stale input from terminal buffer (lxc-attach|tee leaves residual data
|
||||
# that causes read to return immediately with empty input)
|
||||
dd iflag=nonblock if=/dev/tty of=/dev/null 2>/dev/null || true
|
||||
sleep 0.3
|
||||
|
||||
# Read directly from /dev/tty (fresh open = clean state, no inherited corruption)
|
||||
# Read user choice
|
||||
local response=""
|
||||
if read -t 60 -r response </dev/tty 2>/dev/null; then
|
||||
if read -t 60 -r response </dev/tty; then
|
||||
case "${response:-1}" in
|
||||
1)
|
||||
# Remove container
|
||||
|
||||
@@ -286,10 +286,12 @@ error_handler() {
|
||||
echo -en "${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
|
||||
fi
|
||||
|
||||
# Reset terminal state and read directly from /dev/tty (fresh open = clean state)
|
||||
# Reset terminal state and flush stale input from buffer
|
||||
stty sane 2>/dev/null || true
|
||||
dd iflag=nonblock if=/dev/tty of=/dev/null 2>/dev/null || true
|
||||
sleep 0.3
|
||||
local response=""
|
||||
if read -t 60 -r response </dev/tty 2>/dev/null; then
|
||||
if read -t 60 -r response </dev/tty; then
|
||||
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
|
||||
echo ""
|
||||
if declare -f msg_info >/dev/null 2>&1; then
|
||||
|
||||
@@ -934,7 +934,11 @@ upgrade_package() {
|
||||
# ------------------------------------------------------------------------------
|
||||
# Repository availability check with caching
|
||||
# ------------------------------------------------------------------------------
|
||||
declare -A _REPO_CACHE 2>/dev/null || true
|
||||
# Note: Must use -gA (global) because tools.func is sourced inside update_os()
|
||||
# function scope. Plain 'declare -A' would create a local variable that gets
|
||||
# destroyed when update_os() returns, causing "unbound variable" errors later
|
||||
# when setup_postgresql/verify_repo_available tries to access the cache key.
|
||||
declare -gA _REPO_CACHE 2>/dev/null || declare -A _REPO_CACHE 2>/dev/null || true
|
||||
|
||||
verify_repo_available() {
|
||||
local repo_url="$1"
|
||||
|
||||
Reference in New Issue
Block a user