Skip to content

Commit

Permalink
Fix wiping build root for --vm-type podman (#954)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dmach committed Oct 4, 2023
1 parent 22b0154 commit f64b65d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 10 additions & 7 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions build-vm-podman
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit f64b65d

Please sign in to comment.