From f64b65d19779a84dac4d8c5dab5c1e5640853b98 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Wed, 4 Oct 2023 16:55:09 +0200 Subject: [PATCH] Fix wiping build root for --vm-type podman (#954) * Refactor unmounting mounts under build root to unmount_build_root() * Improve mount detection under the build root by adding a space prefix Values in /proc/mounts are separated with a space. Prepending the space to the searched pattern should reduce number of wrong matches * podman: wipe remaining files from the build root --- build | 17 ++++++++++------- build-vm-podman | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build b/build index 2a74edce1..65812bd8e 100755 --- a/build +++ b/build @@ -933,19 +933,22 @@ run_rsync() { fi } -wipe_build_environment() { - if test -n "$VM_TYPE" ; then - vm_img_wipe - else - echo "Wiping build root: '$BUILD_ROOT'" - +unmount_build_root() { # unmount all mounts still in the build root path - for m in $(cat /proc/mounts | grep "$BUILD_ROOT" | awk '{ print $2 }'); do + for m in $(cat /proc/mounts | grep " $BUILD_ROOT" | awk '{ print $2 }'); do if ! umount -n "$m" 2>/dev/null ; then echo "Failed to umount "$m", cannot wipe buildroot" exit 1 fi done +} + +wipe_build_environment() { + if test -n "$VM_TYPE" ; then + vm_img_wipe + else + echo "Wiping build root: '$BUILD_ROOT'" + unmount_build_root rm -rf "$BUILD_ROOT" fi } diff --git a/build-vm-podman b/build-vm-podman index 27f199eb0..743842f8f 100644 --- a/build-vm-podman +++ b/build-vm-podman @@ -80,4 +80,11 @@ vm_sysrq_podman() { vm_wipe_podman() { local name="build_${RECIPEFILE}" podman rm "$name" >/dev/null 2>&1 || true + + echo "Wiping build root: '$BUILD_ROOT'" + unmount_build_root + # calling 'podman unshare' is required because podman creates the files with SubUIDs/SubGIDs + # that differ from user's UID/GID and removing them would normally end up with + # a permission error for any user that is not root + podman unshare rm -rf "$BUILD_ROOT" }