fix: Do not fail if marker cannot be created (#2117)

This commit is contained in:
Kroese
2026-08-08 16:33:27 +02:00
committed by GitHub
parent 9e87e1aefa
commit 43be9024e9
5 changed files with 207 additions and 156 deletions
+52 -32
View File
@@ -195,6 +195,7 @@ selectVersion() {
IFS=$'\t' read -r id index <<< "$record"
[[ "${id,,}" == "${candidate,,}" ]] || continue
hasAnswerFile "$id" || continue
printf '%s\n%s\n' "$id" "$index"
@@ -278,6 +279,7 @@ detectVersion() {
for record in "${images[@]}"; do
IFS=$'\t' read -r id index <<< "$record"
hasAnswerFile "$id" || continue
rank=$(getEditionRank "$id")
@@ -327,7 +329,6 @@ detectLanguage() {
for path in "${paths[@]}"; do
lang=$(xmlstarlet sel -T -t -v "normalize-space(string(($path)[1]))" - 2>/dev/null <<< "$xml") || lang=""
[ -n "$lang" ] && break
done
@@ -502,8 +503,6 @@ createImageDirectory() {
local image="$1"
local directory="$2"
# Treat an existing directory as success; create it only when mdir cannot
# already resolve it.
if mdir -i "$image" "$directory" >/dev/null 2>&1; then
return 0
fi
@@ -560,20 +559,25 @@ createSetupImage() {
fi
for entry in "${entries[@]}"; do
if ! mcopy -Q -s -i "$tmp" "$entry" ::; then
rm -f -- "$tmp"
error "Failed to copy image file: $entry"
return 1
fi
done
if [ -n "$folder" ] || [ -f "$install" ]; then
if ! createImageDirectory "$tmp" "::/\$OEM\$" || ! createImageDirectory "$tmp" "::/\$OEM\$/\$1" ||
! createImageDirectory "$tmp" "$target"; then
rm -f -- "$tmp"
error "Failed to create OEM directory in setup image!"
return 1
fi
fi
if [ -n "$folder" ]; then
@@ -592,11 +596,13 @@ createSetupImage() {
fi
for entry in "${entries[@]}"; do
if ! mcopy -Q -s -o -i "$tmp" "$entry" "$target"; then
rm -f -- "$tmp"
error "Failed to copy OEM file: $entry"
return 1
fi
done
fi
@@ -604,11 +610,13 @@ createSetupImage() {
# Copy the generated overlay script last so it replaces an install.bat from
# the mounted OEM folder when both are present.
if [ -f "$install" ]; then
if ! mcopy -Q -o -i "$tmp" "$install" "$target/install.bat"; then
rm -f -- "$tmp"
error "Failed to replace install.bat in setup image!"
return 1
fi
fi
# Verify that mtools can read the completed filesystem before publishing it.
@@ -773,7 +781,6 @@ detectLegacy() {
detectReactOS() {
local dir="$1"
local marker
marker=$(find "$dir" -maxdepth 2 -type f \
@@ -885,8 +892,8 @@ readIsoImageInfo() {
local image="$2"
local header="$3"
local raw result root xml_count rc
local header_size version
local raw result xml_count rc
local root header_size version
local part_number total_parts image_count
local xml_offset xml_size xml_original xml_flags
local -a bytes=() values=()
@@ -1172,8 +1179,10 @@ findImage() {
fi
for name in install.wim install.esd; do
result=$(find "$sources" -maxdepth 1 -type f -iname "$name" -print -quit) || return 2
[ -n "$result" ] && break
done
if [ ! -f "$result" ]; then
@@ -1222,13 +1231,14 @@ validateEdition() {
# Discard a stale server-edition override when it conflicts with the image
# that was actually detected.
EDITION=""
return 0
}
unknownImage() {
local msg="Failed to determine Windows version from image"
local rc=0
local msg="Failed to determine Windows version from image"
setXML "" || rc=$?
@@ -1252,9 +1262,12 @@ describeImage() {
result=$(printEdition "$DETECTED" "$DETECTED" "Y") || return 1
if [[ "${LANGUAGE,,}" != "en" && "${LANGUAGE,,}" != "en-"* ]]; then
local language
language=$(getLanguage "$LANGUAGE" "desc") || return 1
result+=" ($language)"
fi
printf '%s' "$result"
@@ -1373,7 +1386,6 @@ detectImageInfo() {
detectIsoImage() {
local iso="$1"
local image header image_info rc
# Return 1 only when no directly inspectable WIM/ESD payload is available so
@@ -1405,19 +1417,39 @@ detectIsoImage() {
return 0
}
baseDir() {
local path="${1%/}"
[[ -z "$path" || "$path" == "/" ]] && {
echo "/"
return 0
}
path="${path#/}"
path="${path%%/*}"
echo "/$path"
return 0
}
checkFreeSpace() {
local dir="$1"
local size="$2"
local space size_gb space_gb
local base space size_gb space_gb
base=$(baseDir "$dir")
space=$(df --output=avail -B 1 "$dir" | tail -n 1) || return 1
[[ "$space" =~ ^[[:space:]]*[0-9]+[[:space:]]*$ ]] || {
error "Failed to determine available disk space for $dir!"
if ! space=$(df --output=avail -B 1 "$dir" | tail -n 1); then
error "Failed to check free space in $dir."
return 1
}
fi
if [[ ! "$space" =~ ^[[:space:]]*[0-9]+[[:space:]]*$ ]]; then
error "Failed to determine available disk space for $dir."
return 1
fi
space="${space//[[:space:]]/}"
@@ -1426,8 +1458,9 @@ checkFreeSpace() {
size_gb=$(formatBytes "$size")
space_gb=$(formatBytes "$space")
error "Not enough free space in $STORAGE, have $space_gb available but need at least $size_gb."
error "Not enough free space in $base, have $space_gb available but need at least $size_gb."
return 1
fi
return 0
@@ -1462,7 +1495,7 @@ extractESD() {
fi
if (( size < minSize )); then
error "The downloaded ISO file is too small!"
error "The downloaded ESD file is too small!"
return 1
fi
@@ -1514,8 +1547,7 @@ extractESD() {
bootTotal="${fields[1]:-}"
bootLinks="${fields[2]:-}"
if [[ ! "$bootTotal" =~ ^[0-9]+$ ]] ||
[[ ! "$bootLinks" =~ ^[0-9]+$ ]]; then
if [[ ! "$bootTotal" =~ ^[0-9]+$ ]] || [[ ! "$bootLinks" =~ ^[0-9]+$ ]]; then
error "Cannot read bootdisk size from ESD file!"
return 1
fi
@@ -1537,6 +1569,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
/run/progress.sh "$dir" "$bootSize" "$msg ([P])..." &
@@ -1585,6 +1618,7 @@ extractESD() {
}
fKill "progress.sh"
html "$msg..."
if [[ "${PLATFORM,,}" == "x64" ]]; then
LABEL="CCCOMA_X64FRE_EN-US_DV9"
@@ -1592,9 +1626,6 @@ extractESD() {
LABEL="CPBA_A64FRE_EN-US_DV9"
fi
msg="Extracting image from ESD file"
info "$msg..." && html "$msg..."
index=""
if [[ "${version,,}" == "http"* ]]; then
@@ -1649,10 +1680,8 @@ extractESD() {
fi
installSize=$(( size + installPad ))
/run/progress.sh "$installWim" "$installSize" "$msg ([P])..." &
if ! rm -f -- "$dir/sources/install.wim" "$installWim"; then
fKill "progress.sh"
error "Failed to remove previous Windows installation image!"
return 1
fi
@@ -1660,7 +1689,6 @@ extractESD() {
# Reuse the downloaded solid ESD instead of exporting the selected image.
# Both paths are below $TMP, so this is a same-filesystem rename.
if ! mv -f -- "$iso" "$installWim"; then
fKill "progress.sh"
error "Failed to move downloaded ESD file into the installation media!"
return 1
fi
@@ -1673,7 +1701,6 @@ extractESD() {
wimlib-imagex delete "$installWim" "$image" --soft --quiet || {
ret=$?
fKill "progress.sh"
error "Failed to remove image $image from install.esd!"
return "$ret"
}
@@ -1683,7 +1710,6 @@ extractESD() {
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 "$ret"
}
@@ -1693,7 +1719,6 @@ extractESD() {
-v 'count(/WIM/IMAGE[@INDEX="1"])' -n \
-v 'normalize-space(/WIM/IMAGE[@INDEX="1"]/DESCRIPTION)' -n \
<<< "$result" 2>/dev/null); then
fKill "progress.sh"
error "Cannot verify the prepared install.esd file!"
return 1
fi
@@ -1705,26 +1730,22 @@ extractESD() {
resultEdition="${fields[2]:-}"
if [[ "$resultCount" != "1" ]] || [[ "$resultIndex" != "1" ]]; then
fKill "progress.sh"
error "Prepared install.esd does not contain exactly one image at index 1!"
return 1
fi
if [[ "${version,,}" != "http"* ]] &&
[[ "${resultEdition,,}" != "${edition,,}" ]]; then
fKill "progress.sh"
error "Prepared install.esd does not contain only '$edition' at index 1!"
return 1
fi
fKill "progress.sh"
return 0
}
normalizeBatch() {
local file="$1"
local bom tmp encoding
[ ! -s "$file" ] && return 0
@@ -1768,7 +1789,6 @@ reportBatchMatches() {
local suggestion="$5"
local matches line
matches=$(grep -Pin "$pattern" "$file" || true)
[ -n "$matches" ] || return 0