build(qemu): use mktemp -d and trap for safe clone directory

Replace rm -rf qemu + clone-into-relative-path with mktemp -d so the
build never touches a pre-existing qemu/ directory in the bind-mounted
host working directory.  The trap ensures cleanup on any exit path.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
Zvonko Kaiser
2026-07-14 19:32:57 +00:00
parent 485286440f
commit 8bc351e971

View File

@@ -26,11 +26,10 @@ HYPERVISOR_NAME="${HYPERVISOR_NAME:-}"
PREFIX="${PREFIX:-}"
PKGVERSION=${PKGVERSION:-}
# This script always runs inside a dedicated build container (see
# static-build/qemu/Dockerfile), so rm -rf of a relative path is safe.
rm -rf qemu
git clone --depth=1 "${QEMU_REPO}" qemu
pushd qemu
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT
git clone --depth=1 "${QEMU_REPO}" "${workdir}/qemu"
pushd "${workdir}/qemu"
git fetch --depth=1 origin "${QEMU_VERSION_NUM}"
git checkout FETCH_HEAD
scripts/git-submodule.sh update meson capstone