Skip to content

Commit 065f34a

Browse files
authored
build.func: allow default.vars to raise var_cpu/var_ram/var_disk above app baseline (#16704)
1 parent c1929dc commit 065f34a

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

misc/build.func

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,12 @@ base_settings() {
12081208
# - Used by default_var_settings and app defaults loading
12091209
# - Only loads whitelisted var_* keys
12101210
# - Optional force parameter to override existing values (for app defaults)
1211+
# - Optional protected list preserves genuinely user-exported var_* values
12111212
# ------------------------------------------------------------------------------
12121213
load_vars_file() {
12131214
local file="$1"
1214-
local force="${2:-no}" # If "yes", override existing variables
1215+
local force="${2:-no}" # If "yes", override existing variables
1216+
local protected="${3:-}" # space-separated var_* keys the user genuinely exported before this file loaded; never overwritten
12151217
[ -f "$file" ] || return 0
12161218
msg_info "Loading defaults from ${file}"
12171219

@@ -1231,6 +1233,13 @@ load_vars_file() {
12311233
return 1
12321234
}
12331235

1236+
# Protected check helper (genuinely user-exported vars, see $protected above)
1237+
_is_protected() {
1238+
local k="$1" p
1239+
for p in $protected; do [ "$k" = "$p" ] && return 0; done
1240+
return 1
1241+
}
1242+
12341243
local line key val
12351244
while IFS= read -r line || [ -n "$line" ]; do
12361245
line="${line#"${line%%[![:space:]]*}"}"
@@ -1435,9 +1444,19 @@ load_vars_file() {
14351444
esac
14361445
fi
14371446

1438-
# Set variable: force mode overrides existing, otherwise only set if empty
1447+
# Set variable: force mode overrides existing, otherwise only set if empty.
1448+
# Exception: var_cpu/var_ram/var_disk are always applied here (unless the
1449+
# user genuinely exported them beforehand, per $protected) even though the
1450+
# app script already declared its own baseline for them - base_settings()
1451+
# reconciles the final floor against APP_DEFAULT_* afterward, so this file
1452+
# must be allowed to raise them instead of being silently blocked by the
1453+
# app's own pre-set value.
14391454
if [[ "$force" == "yes" ]]; then
14401455
export "${var_key}=${var_val}"
1456+
elif _is_protected "$var_key"; then
1457+
:
1458+
elif [[ "$var_key" == "var_cpu" || "$var_key" == "var_ram" || "$var_key" == "var_disk" ]]; then
1459+
export "${var_key}=${var_val}"
14411460
else
14421461
[[ -z "${!var_key+x}" ]] && export "${var_key}=${var_val}"
14431462
fi
@@ -1597,7 +1616,7 @@ EOF
15971616
msg_error "default.vars not found after ensure step"
15981617
return 252
15991618
}
1600-
load_vars_file "$dv"
1619+
load_vars_file "$dv" "no" "${!_HARD_ENV[*]}"
16011620

16021621
# 3) Map var_verbose → VERBOSE
16031622
if [[ -n "${var_verbose:-}" ]]; then

0 commit comments

Comments
 (0)