fix: Simplify error propagation boundaries (#2104)

This commit is contained in:
Kroese
2026-08-07 19:52:06 +02:00
committed by GitHub
parent ff8c17ad04
commit be96767802
3 changed files with 176 additions and 231 deletions
+39 -56
View File
@@ -369,7 +369,7 @@ detectVersion() {
local -a selection_order=()
local result="" index=""
getVersions "$xml" versions bases groups image_indexes || return 1
getVersions "$xml" versions bases groups image_indexes || return
if [ "${#versions[@]}" -eq 0 ]; then
printf '%s\n%s\n' "$result" "$index"
@@ -924,7 +924,6 @@ detectReactOS() {
findIsoImage() {
local iso="$1"
local path
# Prefer install.wim when both payload forms are present.
@@ -1060,15 +1059,7 @@ readIsoImageInfo() {
result=$(udfread range --ignore-case "$iso" "$image" "$xml_offset" "$xml_size" \
2>/dev/null | iconv -f UTF-16LE -t UTF-8 2>/dev/null
) || {
local rc=$?
if (( rc >= 129 )); then
exit "$rc"
fi
return 1
}
) || return
[ -n "$result" ] || return 1
@@ -1209,15 +1200,9 @@ readImageInfo() {
local wim="$1"
local result=""
result=$(wimlib-imagex info --xml "$wim" | iconv -f UTF-16LE -t UTF-8) || {
local rc=$?
if (( rc >= 129 )); then
exit "$rc"
fi
if ! result=$(wimlib-imagex info --xml "$wim" | iconv -f UTF-16LE -t UTF-8); then
result=""
}
fi
if [ -z "$result" ]; then
error "Failed to read Windows image information!"
@@ -1349,10 +1334,10 @@ detectImageInfo() {
checkPlatform "$image_info" || exit 67
suggested=$(getSuggestion) || return 1
suggested=$(getSuggestion) || return
local output
output=$(detectVersion "$image_info" "$suggested") || return 1
output=$(detectVersion "$image_info" "$suggested") || return
local -a detected=()
mapfile -t detected <<< "$output"
@@ -1360,19 +1345,19 @@ detectImageInfo() {
DETECTED="${detected[0]:-}"
index="${detected[1]:-}"
validateEdition || return 1
validateEdition || return
if [ -z "$DETECTED" ]; then
unknownImage || return 1
unknownImage || return
return 0
fi
detectLanguage "$image_info" "$index" || return 1
detectLanguage "$image_info" "$index" || return
desc=$(describeImage) || return 1
desc=$(describeImage) || return
info "Detected: $desc"
configureImage "$index" "$desc" || return 1
configureImage "$index" "$desc" || return
return 0
}
@@ -1381,18 +1366,14 @@ detectIsoImage() {
local iso="$1"
local image header image_info rc
local image header image_info
# Return 1 only when no directly inspectable WIM/ESD payload is available so
# the caller may extract the media. Metadata parsing/configuration errors use 2.
image=$(findIsoImage "$iso") || return 1
header=$(readWimHeader "$iso" "$image") || return 2
image_info=$(readIsoImageInfo "$iso" "$image" "$header") || {
rc=$?
(( rc >= 129 )) && return "$rc"
return 2
}
image_info=$(readIsoImageInfo "$iso" "$image" "$header") || return 2
info "Detecting version from ISO image..."
detectImageInfo "$image_info" || return 2
@@ -1471,11 +1452,12 @@ extractESD() {
return 1
fi
if ! xml=$(wimlib-imagex info "$iso" --xml 2>/dev/null |
iconv -f UTF-16LE -t UTF-8 2>/dev/null); then
xml=$(wimlib-imagex info "$iso" --xml 2>/dev/null |
iconv -f UTF-16LE -t UTF-8 2>/dev/null) || {
ret=$?
error "Cannot read ESD file information!"
return 1
fi
return "$ret"
}
# Microsoft download ESDs use images 1-3 for setup media, WinPE, and Windows
# Setup; images 4 and higher contain installable editions. Read all metadata
@@ -1531,7 +1513,7 @@ extractESD() {
# installation media. Peak additional usage consists of the extracted setup
# files and boot.wim, plus the final ISO containing those files and the ESD.
local freeSpace=$(( size + 2 * (bootSize + wimSize) + spacePad ))
checkFreeSpace "$dir" "$freeSpace" || return 1
checkFreeSpace "$dir" "$freeSpace" || return
/run/progress.sh "$dir" "$bootSize" "$msg ([P])..." &
@@ -1540,7 +1522,7 @@ extractESD() {
ret=$?
fKill "progress.sh"
error "Extracting $desc bootdisk failed ($ret)"
return 1
return "$ret"
}
fKill "progress.sh"
@@ -1559,7 +1541,7 @@ extractESD() {
ret=$?
fKill "progress.sh"
error "Adding WinPE failed ($ret)"
return 1
return "$ret"
}
fKill "progress.sh"
@@ -1575,7 +1557,7 @@ extractESD() {
ret=$?
fKill "progress.sh"
error "Adding Windows Setup failed ($ret)"
return 1
return "$ret"
}
fKill "progress.sh"
@@ -1602,9 +1584,9 @@ extractESD() {
return 1
fi
checkPlatform "$xml" || return 1
checkPlatform "$xml" || return
output=$(detectVersion "$installXml") || return 1
output=$(detectVersion "$installXml") || return
mapfile -t detected <<< "$output"
index="${detected[1]:-}"
@@ -1665,20 +1647,22 @@ extractESD() {
(( image == index )) && continue
if ! wimlib-imagex delete "$installWim" "$image" --soft --quiet; then
wimlib-imagex delete "$installWim" "$image" --soft --quiet || {
ret=$?
fKill "progress.sh"
error "Failed to remove image $image from install.esd!"
return 1
fi
return "$ret"
}
done
if ! result=$(wimlib-imagex info "$installWim" --xml 2>/dev/null |
iconv -f UTF-16LE -t UTF-8 2>/dev/null); then
result=$(wimlib-imagex info "$installWim" --xml 2>/dev/null |
iconv -f UTF-16LE -t UTF-8 2>/dev/null) || {
ret=$?
fKill "progress.sh"
error "Cannot verify the prepared install.esd file!"
return 1
fi
return "$ret"
}
if ! metadata=$(xmlstarlet sel -t \
-v 'count(/WIM/IMAGE)' -n \
@@ -2009,7 +1993,7 @@ buildImage() {
local cat="BOOT.CAT"
local log="/run/shm/iso.log"
local base size desc failed=""
local base size desc rc=0
if [ -f "$BOOT" ]; then
error "File $BOOT does already exist?!" && return 1
@@ -2118,15 +2102,14 @@ buildImage() {
fi
if ! genisoimage "${args[@]}" -quiet "$dir" 2> "$log"; then
failed="y"
fi
genisoimage "${args[@]}" -quiet "$dir" 2> "$log" || rc=$?
fKill "progress.sh"
if [ -n "$failed" ]; then
if (( rc != 0 )); then
[ -s "$log" ] && echo "$(<"$log")"
error "Failed to build image!" && return 1
error "Failed to build image!"
return "$rc"
fi
local err=""
@@ -2139,7 +2122,7 @@ buildImage() {
echo "$err"
fi
mv -f "$out" "$BOOT" || return 1
mv -f "$out" "$BOOT" || return
if ! setOwner "$BOOT"; then
warn "Failed to set the owner for \"$BOOT\" !"