refactor: simplify RDS internals (#692)

This commit is contained in:
Julian Sommer
2026-08-04 14:42:45 +10:00
committed by GitHub
parent 2e09461080
commit 615578a2e7
14 changed files with 32 additions and 131 deletions
+2 -2
View File
@@ -83,7 +83,7 @@ await_data_disk() {
# when it could not find out: a blkid that is missing, errored or pointed at an
# absent node prints exactly what a blank disk prints, so only the status decides.
fstype_of() {
if _out=$(blkid "$1" 2>/dev/null); then
if _out=$(blkid -o value -s TYPE "$1" 2>/dev/null); then
_rc=0
else
_rc=$?
@@ -91,7 +91,7 @@ fstype_of() {
# 0 is a signature found, 2 a clean probe that found none. Anything else
# means the probe did not run, which is not an answer.
[ "${_rc}" -eq 0 ] || [ "${_rc}" -eq 2 ] || return 1
printf '%s' "${_out}" | sed -n 's/.*[[:space:]]TYPE="\([^"]*\)".*/\1/p'
printf '%s' "${_out}"
}
# Partitions appear as child directories of the disk in sysfs, which needs no
@@ -16,18 +16,19 @@ trap 'rm -rf "${WORK}"' EXIT
STUBBIN="${WORK}/bin"
mkdir -p "${STUBBIN}"
# blkid stub: prints a real blkid's line for any device listed in FS_TABLE as
# "<dev> <fstype>", and exits non-zero for one that holds no filesystem.
# blkid stub: prints the requested filesystem type value for any device listed
# in FS_TABLE as "<dev> <fstype>", and exits non-zero when none is present.
cat > "${STUBBIN}/blkid" <<'EOF'
#!/bin/sh
# BLKID_RC simulates a probe that could not run at all — 127 is a blkid missing
# from the image, 4 an internal error. Both print nothing, which is precisely
# what a genuinely blank disk prints, so only the exit status separates them.
[ "${BLKID_RC:-0}" = "0" ] || exit "${BLKID_RC}"
dev="$1"
[ "$1" = "-o" ] && [ "$2" = "value" ] && [ "$3" = "-s" ] && [ "$4" = "TYPE" ] || exit 4
dev="$5"
fstype=$(awk -v d="${dev}" '$1 == d { print $2 }' "${FS_TABLE}" 2>/dev/null)
[ -n "${fstype}" ] || exit 2
echo "${dev}: UUID=\"1234-5678\" TYPE=\"${fstype}\""
printf '%s\n' "${fstype}"
EOF
# mkfs.ext4 stub: records the call and marks the device formatted, so a mount