fix(filesystems): add cleanup trap for temp btrfs mount
Add trap to ensure temp mount is cleaned up if btrfs subvolume creation fails. Without this, failures leave mounted filesystems and orphaned directories, blocking retry attempts. Use mountpoint -q for robust mount detection before cleanup. Decision: Use local trap within format_filesystems to avoid interfering with main error handler. Reset trap after successful completion to prevent double cleanup. Trade-off: Slightly more complex code vs guaranteed cleanup on error paths.
This commit is contained in:
parent
c9fbc5486c
commit
c303a75192
@ -64,6 +64,18 @@ format_filesystems() {
|
||||
local temp_mount
|
||||
temp_mount="/tmp/void-wrapper-btrfs"
|
||||
mkdir -p "$temp_mount"
|
||||
|
||||
# Ensure cleanup on error
|
||||
cleanup_temp_mount() {
|
||||
if mountpoint -q "$temp_mount" 2>/dev/null; then
|
||||
umount "$temp_mount" || log_warn "Failed to unmount temp mount: $temp_mount"
|
||||
fi
|
||||
if [[ -d "$temp_mount" ]]; then
|
||||
rmdir "$temp_mount" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup_temp_mount EXIT
|
||||
|
||||
mount "$root_device" "$temp_mount"
|
||||
btrfs subvolume create "$temp_mount/@"
|
||||
btrfs subvolume create "$temp_mount/@home"
|
||||
@ -73,6 +85,7 @@ format_filesystems() {
|
||||
btrfs subvolume create "$temp_mount/@swap"
|
||||
umount "$temp_mount"
|
||||
rmdir "$temp_mount"
|
||||
trap - EXIT
|
||||
else
|
||||
log_info "Formatting root as ext4 on $root_device"
|
||||
mkfs.ext4 -L "$ROOT_LABEL" "$root_device"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user